Page 1 of 1

Copying files to own seperate folders?

Posted: 23 Feb 2009 23:19
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.

Re: Copying files to own seperate folders?

Posted: 24 Feb 2009 16:58
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

Re: Copying files to own seperate folders?

Posted: 28 Apr 2009 14:46
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";

Re: Copying files to own seperate folders?

Posted: 06 Oct 2012 12:39
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.