Page 1 of 1

Create Folder Based Off Date of Files

Posted: 14 Aug 2010 17:08
by SkyFrontier
Ok, here's my first complex take on scripts... (Stefan's revamped code, in fact...)

Code: Select all

//this is valid for only ONE selected item!
"Create Those Folders"

    //Ask user to prepend NAME to folder
    $name = input("Enter name of the folder","This will result in: 'NAME yyyy-mm-dd'; Empty for DATE only as name of the folder", "NAME",, chr(12));

    //Get Location of where Folders will be created: Use "<curpath>" instead of "C:\", if you prefer to start there.
    $dir=InputFolder("C:\", "Where would you like to create these folders?");

    //Get the list of selected items, folders or files:
    $LIST = Report("{modified yyyy-mm-dd}", 1);

    //For Each Item in Items:
    $Loop = 1;
    while(1)
    {
      //Get next ITEM:
      $ITEM = gettoken($LIST, $Loop, "<crlf>");
      //If ITEM is nothing end this script:
      IF ($ITEM==""){break;}

      //Get the BASE of the item name, i.e. drop all after including the last dot:
      $Folder = regexreplace("$ITEM", "(.+)(\..+)","$1");
     
      //Create new item, here as folder:
      new($dir\$Name$Folder, dir);
     
     //next iteration:
    incr $Loop;
    }
-but I'd like to improve it!
>"$name = " could tell the script if the variable (if present) will be appended or prepended, like
Input: ANYTHING*
or
Input: *ANYTHING,
being ( * ) equivalent to "$LIST = Report("{modified yyyy-mm-dd}""

>It could grab the date of the first selected item *only* on top of the list, ie, if I sort a bunch of files by name and want to create a folder based off their modification date, the script should grab the top list item's date only; same for sorting by last modified or anything else. But this does NOT means that I want the "line 1" file... it's the first top file out of the selected items...

>Alternatively, the script could ask me if I want to copy/move/backup selected items to newly created folder, or do nothing. AND ask if user wants to use current date instead of top item's modified date.

Any help, please...?