Page 1 of 2

Help ! Create new empty folders

Posted: 21 Oct 2009 13:20
by Ysl
Hi

Would it be possible to have a script that copy the names of all the folders selected and create the same folders in another main folder but only the name of the folders must be duplicated, not the contents.

Thanks for your help

Ysl

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 13:38
by RalphM
If the folder structure is dynamic (i.e. you need to copy various different folder collections) then a script would be the way to go, but I leave it to the experts to come up with a one-line script to do it.
But, if the structure is always the same folder collection you need in various places, then you should look into "Edit/New Items", which lets you create a complete folder structure (even with some files in it) and copy this structure to the current folder with a single click.

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 14:09
by TheQwerty

Code: Select all

"Create Those Folders"
  //Get Location of where Folders will be created.
  $dir=InputFolder("<curpath>", "Where would you like to create these folders?");
  //Generate and execute a script to create each new item.
  Load(Report("New('$dir\{Name}','dir');"),, "s");
You could also use File->To Clipboard->Item Name(s) in conjunction with Edit->New->New Folders.

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 14:38
by Stefan
EDIT: Sorry, i was to slow with formating, so others are faster.


Ysl wrote:Hi
> Would it be possible to have a script that copy the names of all the folders selected
http://88.191.26.34/XYwiki/index.php/Sc ... info%28%29
(i hope you don't mean "with all sub folders" ?)

> and create the same folders
http://88.191.26.34/XYwiki/index.php/Sc ... ent:_while
http://88.191.26.34/XYwiki/index.php/Sc ... mmand:_new

> in another main folder
http://88.191.26.34/XYwiki/index.php/Sc ... mand:_goto


> Thanks for your help
HTH? :P




BTW: here is my test code, created with the help of this community, the wiki and XYs help:

NOTE: It has no error handling! It works for me, but please test before you would use it for real work

Code: Select all

$items = getinfo("selecteditemsnames","?"); //list names of selected items with an "?" as delimiter
 $items = regexreplace( $items, '(.+).', "$1"); //drop last delim
  //msg $items;
 
 GoTo "C:\Temp\";                   // goto other location
 //GoTo inputfolder();              // prompt for folder

 while strlen($items)>0 {           // as long as there is any content
   $delimPos = strpos($items, "?"); // Get pos of delimiter
   IF ($delimPos=='-1'){            // If no delim anymore
      $folder = $items             
   }else{
      $folder =  substr($items,0,$delimPos); // first part of $items till delim
   }
   //msg $folder;
   new $folder, dir;   // create folder
   
   IF ($delimPos=='-1'){           // If no delim anymore
       $items =                    // emtpy the var
   }else{
       $items = substr($items, $delimPos +1); // fill var with rest of items only
       //msg $items;
    }
   }

OMG, Update
Today i would code it like this:

Code: Select all

$items = getinfo("selecteditemsnames","|");
 	$Count = getinfo("countselected");

 	GoTo inputfolder("<curpath>"); // prompt for folder

 	$Loop=1;
 	while($Loop<=$Count)
 	{
 		$folder = gettoken($items, $Loop, "|");
  		new $folder, dir;   // create folder
	incr $Loop;
 	}

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 14:44
by TheQwerty
Oppsy... I forgot the Selected Only parameter on the Report() call. :oops:

Should be:

Code: Select all

"Create Those Folders"
  //Get Location of where Folders will be created.
  $dir=InputFolder("<curpath>", "Where would you like to create these folders?");
  //Generate and execute a script to create each new item.
  Load(Report("New('$dir\{Name}','dir');", 1),, "s");

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 14:46
by Stefan
O.K.! It's time for me to get familiar with this 'Report' thinggy. :lol:

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 14:55
by admin
Folks, this is built in! Check Hep for Create Folder(s) Here:

Create Folder(s) Here

Drag a folder (or several folders) onto a target location and create a copy of this folder without any of its contents in the target location. It's the flat version of "Create Branche(s) Here" (below). Very handy feature to quickly create some folders by simply drag-dropping them to their birth-place.

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 15:01
by Stefan
admin wrote:Folks, this is built in!
Thanks. But not as script command :wink:

Can getinfo or report be extended to working recursive?

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 15:05
by admin
Stefan wrote:
admin wrote:Folks, this is built in!
Thanks. But not as script command :wink:

Can getinfo or report be extended to working recursive?
I don't know. :P (No time for this now...)

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 15:27
by Ysl
Thank you all for your quick reply and yes indeed, this was build in !

The problem is there are too much (?!) features build in XYplorer to know them all !

Thanks again

Ysl

Re: Help ! Create new empty folders

Posted: 21 Oct 2009 16:29
by TheQwerty
admin wrote:Folks, this is built in! Check Hep for Create Folder(s) Here
I thought it was built-in somewhere but didn't check help.

I saw it on the d'n'd menu, however, since you haven't given those items descriptions that show up in the status bar I had no clue what they do! :twisted:

Err.. honestly I didn't even check there. :P

Re: Help ! Create new empty folders

Posted: 26 Jul 2010 21:17
by SkyFrontier
Is there a way to improve this:

Code: Select all

"Create Those Folders"
  //Get Location of where Folders will be created.
  $dir=InputFolder("<curpath>", "Where would you like to create these folders?");
  //Generate and execute a script to create each new item.
  Load(Report("New('$dir\{Name}','dir');", 1),, "s");
so it can create folders WITHOUT "pseudo-extensions" and based off selected files only, different from current "take all folder's content as base name for new folders" code?

Thanks!

Re: Help ! Create new empty folders

Posted: 27 Jul 2010 08:49
by Stefan
SkyFrontier wrote:Is there a way to improve this:

Code: Select all

"Create Those Folders"
  //Get Location of where Folders will be created.
  $dir=InputFolder("<curpath>", "Where would you like to create these folders?");
  //Generate and execute a script to create each new item.
  Load(Report("New('$dir\{Name}','dir');", 1),, "s");
so it can create folders WITHOUT "pseudo-extensions"
and based off selected files only, different from current "take all folder's content as base name for new folders" code?

Thanks!
That code works already for selected items only.

To drop the folder "extensions" i had first {BaseName} in mind, but
{Basename}
- The field is set to the base name of the file (file name without extension).
- Folder names are returned unchanged.



So i use an regex here to drop all chars after and included the last dot:

Code: Select all

"Create Those Folders"
    //Get Location of where Folders will be created:
    $dir=InputFolder("<curpath>", "Where would you like to create these folders?");

    //Get the list of selected items, folders or files:
    $LIST = Report("{Name}<crlf>", 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\$Folder, dir);
      
     //next iteration:
    incr $Loop;
    }

HTH? :lol:

Re: Help ! Create new empty folders

Posted: 27 Jul 2010 09:46
by SkyFrontier
Purrrrfect...
Wow.
Works even if base names are taken out of other folders' names and even name collision is avoided appending "-01" as ending.
...now will try to make a simpler version, no-GUI, just a point-and-shoot tools... I love choices!
Thanks, Stefan!
As a side note... take a look at today's Giveaway. It seems a pretty good program. (Don't know if you still check out that site, but... there you go!)

EDIT:
In the event of someone wishing to create a CTB/CKS for it, with no-GUI to interact with (point-and-shoot scripts! :D ), here it goes:

Code: Select all

"Create Those Folders"

    //Get the list of selected items, folders or files:
    $LIST = Report("{Name}<crlf>", 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\$Folder, dir);
     
     //next iteration:
    incr $Loop;
    }
All credit goes to Stefan.

Re: Help ! Create new empty folders

Posted: 27 Jul 2010 12:15
by SkyFrontier
Stefan,
Is it possible to have this matter handled in another approach?
Script could ask user:

Code: Select all

Base name ("BackupTEMP_0015", for instance)
Number of folders to be created ("X")
Consider that BackupTEMP_0015 is a starting indicator, so the next "X" will append like:
Base: BackupTEMP_0015; X = 7; Output folders: BackupTEMP_0016...BackupTEMP_0022
Another way to achieve that (if the lasting numbers can't be easily checked by that script) would be asking user for a third input, so:

Code: Select all

Base name: ("BackupTEMP_", for instance)
Number of folders to be created: ("X")
Starting with: (0015)
I was wondering on a more wider range of usage for such script... More USUAL, perhaps.
Thanks much!

EDIT: Ideally this cannot be limited to 4 digit format... "XXXX" or "YYY" is another base indicator. User defined.