Help ! Create new empty folders

Discuss and share scripts and script files...
Ysl
Posts: 158
Joined: 03 Jan 2007 22:22

Help ! Create new empty folders

Post 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

RalphM
Posts: 2042
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Help ! Create new empty folders

Post 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.
Ralph :)
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Help ! Create new empty folders

Post 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.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Help ! Create new empty folders

Post 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;
 	}
Last edited by Stefan on 26 Jul 2010 21:23, edited 1 time in total.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Help ! Create new empty folders

Post 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");

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Help ! Create new empty folders

Post by Stefan »

O.K.! It's time for me to get familiar with this 'Report' thinggy. :lol:

admin
Site Admin
Posts: 64875
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Help ! Create new empty folders

Post 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.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Help ! Create new empty folders

Post 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?

admin
Site Admin
Posts: 64875
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Help ! Create new empty folders

Post 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...)

Ysl
Posts: 158
Joined: 03 Jan 2007 22:22

Re: Help ! Create new empty folders

Post 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

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Help ! Create new empty folders

Post 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

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help ! Create new empty folders

Post 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!
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...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Help ! Create new empty folders

Post 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:

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help ! Create new empty folders

Post 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.
Last edited by SkyFrontier on 27 Jul 2010 13:06, edited 1 time in total.
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...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Help ! Create new empty folders

Post 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.
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