Page 1 of 1

Script to move all files in subfolders to other folder?

Posted: 19 Aug 2016 15:10
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

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

Posted: 19 Aug 2016 15:29
by highend
And how should a script know which files to process and where to move them? Where is the pattern to automate that?

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

Posted: 19 Aug 2016 17:20
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

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

Posted: 19 Aug 2016 17:39
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;

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

Posted: 18 Oct 2025 17:13
by kubbie
highend wrote: 19 Aug 2016 17:39 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;
This scripy moved the whole folder and not the contents inside of the sub folders?

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

Posted: 20 Oct 2025 08:39
by bossi
i think highend misunderstood , i assume you meant to flatten a folder , use forum search , there are tons of scripts )