Copying files to own seperate folders?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kartal
Posts: 208
Joined: 14 Aug 2008 18:06

Copying files to own seperate folders?

Post by kartal »

Hi

Is it possible to copy selected files to their own seperate folders(per file). I would like folders to be named based on files as well.

ale
Posts: 127
Joined: 19 Feb 2009 23:23
Location: Italy

Re: Copying files to own seperate folders?

Post by ale »

I have no knowledge of scripting :oops: it's only the second one I write, but I can offer this humble one line script waiting a better and complete solution

Code: Select all

$a = <curbase>.'.'.<curext>; new <curbase>, dir; copyto <curbase>, <curpath>.'\'.$a;
If we have one file selected and his name is hello.ext, it will create a folder called hello and it will copy the file inside it

admin
Site Admin
Posts: 50945
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Copying files to own seperate folders?

Post by admin »

ale wrote:I have no knowledge of scripting :oops: it's only the second one I write, but I can offer this humble one line script waiting a better and complete solution

Code: Select all

$a = <curbase>.'.'.<curext>; new <curbase>, dir; copyto <curbase>, <curpath>.'\'.$a;
If we have one file selected and his name is hello.ext, it will create a folder called hello and it will copy the file inside it
Works well it seems! Here's a little simplification using <curname>

Code: Select all

$a = <curname>; new <curbase>, dir; copyto <curbase>, "<curpath>\$a";
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

kiwichick
Posts: 277
Joined: 08 Aug 2012 04:14

Re: Copying files to own seperate folders?

Post by kiwichick »

This is great. I do this sort of thing all the time. I've modified it to work on multiple selections so each selected item will be copied to its own named folder. Of course copyto can just as easily be replaced with moveto which is my preferred action.

Code: Select all

//creates named folder for each
foreach($file, get("SelectedItemsPathNames", "|"), "|") {
   $folder = getpathcomponent($file, "base");
   new $folder, dir; 
//copies each to named folder   
   $path = getpathcomponent($file, "path");
   $name = getpathcomponent($file, "file");
   copyto "$folder", "$path\$name";}
I'm just a wee bit proud actually :biggrin: I think I've done pretty well for a relative newbie. I'd love to know if there is a better/shorter method I could have used.

Post Reply