Create Folder Based Off Date of Files

Discuss and share scripts and script files...
Post Reply
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Create Folder Based Off Date of Files

Post 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...?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply