Author Topic: Create date folders for a whole year  (Read 19223 times)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Create date folders for a whole year
« on: December 15, 2012, 13:36:38 »
Somebody ask me for how to create date folders for a whole year using script.
Well here is how you do it.


This script will create 365 date folders. 

D:\Test\2013-01-01
D:\Test\2013-01-02
D:\Test\2013-01-03
and so on

Code: [Select]
// set time to "2013-01-01 00:00:00" - the value is seconds from 1970-01-01 00:00:00 - use http://www.epochconverter.com/ to get the start value
@var $time = 1356998400;

// Path to where you want to create the folders
@var $FolderBaseName = "D:\\Test\\";

@var $date = "";
@var $folder;

@var $n = 0;
for( $n = 0; $n < 365; $n++ )
{
 $date = FormatDate( "yyyy-MM-dd" , $time );
 
 $folder = $FolderBaseName ^ $date;
 MC.Filesystem.Makedir PATH="{$folder}"

 // Increase value by the seconds of a day
 $time = $time + 86400;
}

sl23

  • Guest
Re: Create date folders for a whole year
« Reply #1 on: March 14, 2015, 13:17:36 »
I'm interested in using this, but just for months not days, I imagine it can be adapted for that purpose?

If so,  I'd like to look into how to adapt it myself as a starting point in learning a little about scripts. Do you know of any good resources?

Thanks

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Create date folders for a whole year
« Reply #2 on: March 14, 2015, 14:58:07 »
Since there are only 12 months. it is faster to just write the script with hardcoded date..

Code: [Select]
@var $FolderBaseName = "D:\\Test\\";

$folder = $FolderBaseName ^ "2015-01";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-02";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-03";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-04";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-05";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-06";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-07";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-08";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-09";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-10";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-11";
MC.Filesystem.Makedir PATH="{$folder}"
$folder = $FolderBaseName ^ "2015-12";
MC.Filesystem.Makedir PATH="{$folder}"