Script to move all files in subfolders to other folder?

Discuss and share scripts and script files...
Post Reply
Vocalpoint
Posts: 163
Joined: 06 Nov 2009 14:01

Script to move all files in subfolders to other folder?

Post by Vocalpoint »

Quite often I find myself needing to pick through a series of subfolders to move the files within - to a completely different subfolder.

Example structure:

Parent Folder

With the following underneath it

Sub 1
Sub 2
Sub 3
Sub 4
Sub 5

Is there anyway via scripting (or natively) that XY can instantly move all the files that are sitting in Sub1-4 over to Sub 5 - and then delete the Sub 1-4 folders in one quick pass?

Appreciate any insights

Cheers!

VP

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to move all files in subfolders to other folder?

Post by highend »

And how should a script know which files to process and where to move them? Where is the pattern to automate that?
One of my scripts helped you out? Please donate via Paypal

Vocalpoint
Posts: 163
Joined: 06 Nov 2009 14:01

Re: Script to move all files in subfolders to other folder?

Post by Vocalpoint »

highend wrote:And how should a script know which files to process and where to move them? Where is the pattern to automate that?
Totally understand. In this case - there need not be any focus on "which" files (I always want all files anyway).

Let me rephrase - is there any way to highlight a series of folders and "cut" ALL files from ALL selected folders and then paste ALL files into a new destination (that I would select)? And then delete all the empty folders?

My issue right now is that I have to actually go into each subfolder, cut (or grab) all the files and then paste/drop them into another intended target.

If I have 20 or 30 or 50 subfolders - you can see how this gets annoying - fast - having to go into each folder, grab/cut the files, paste/move to the new target and then have to delete each folder manually.

VP

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to move all files in subfolders to other folder?

Post by highend »

1. Select all the subfolders from which the files should be moved to a different folder
2. Execute the script and choose the folder where the files should be moved

Be warned! moveto doesn't support "on collision" -> Files are overwritten when they have the same name
If you don't want that, use backupto instead...

Try it with testfolders first...

Code: Select all

    $folders = <get SelectedItemsPathNames |>;
    $destination = inputfolder(<curpath>, "Select the destination folder...");

    $fileList = "";
    foreach($folder, $folders) {
        $fileList = $fileList . listfolder($folder, , 1) . "|";
    }
    moveto($destination, $fileList);
    delete 1, 0, $folders;
One of my scripts helped you out? Please donate via Paypal

Post Reply