How to move multiple files from multiple sub-folders down one level?

Hi, here is a tricky one. Similar questions have been asked around but I couldn't find any satisfactory result or others that seemed good but where written in Python code (which I know nothing about).

I need to repeat this action thousands of times and if such an action can be done automatically, it would be a great time saver !

Let's say you have a tree that looks like that :

C:\Main Folder\1st SubFolder 01\2nd SubFolder01*.*
C:\Main Folder\1st SubFolder 02\2nd SubFolder02*.*
C:\Main Folder\1st SubFolder 03\2nd SubFolder03*.*
C:\Main Folder\1st SubFolder 04\2nd SubFolder04*.*
etc.

What I need is to move all files down one level in the tree to get that result :

C:\Main Folder\1st SubFolder 01*.*
C:\Main Folder\1st SubFolder 02*.*
C:\Main Folder\1st SubFolder 03*.*
C:\Main Folder\1st SubFolder 04*.*

Please note that the batch (or script, etc. I don't know what kind of code the solution would need) should work no matter what the folder names are. The idea is to move any and all files from the second sub-folders up the tree.

Could someone please explain how such a thing could be automated ?P.S : I'm a total noob when it comes to batch or script, etc. So please if you have a method, explain it as clearly as possible :wink:

Thanks in advance !

If you want to move everything in each selected folder up a level, then delete that folder (if it is now empty), see this reply:

"then delete that folder (if it is now empty)"
well, no, none of those subfolders are empty. As my aim is to move their content down one level.
I checked the "making folder for a file based on file name" and don't really see the relation with what I'm trying to do : take all existing files from (not) empty subfolders and move them down the tree.

May I precise that I'm not at all used to batch or scripts and even if this code could work, I doubt I'd know where to type it (in a .bat file ? From the MS-DOS command prompt ??)

When those folders will be empty, I have another program that deletes all empty folders in a given directory. So that part won't be an issue.

P.S : I've seen terrible forums, really good ones. But this one is truly impressive. You're really a hell of a good coder !

well, no, none of those subfolders are empty.

If you take everything in the images sub-folders and move them up* to the SubFolder 0x levels, then the images folders will now be empty.

(*Terminology: Moving a file from a sub-folder to a parent folder is moving it up the tree. Moving it down would mean moving it into a deeper sub-folder.)

"up the tree"
sorry about my lack of terminology knowledge. This for sure didn't help with my google searching for a solution :wink:
I saw many posts around about moving all files into one single folder. This is of course ultra simple to do and is not what I'm looking for (I precise this even if it's obvious as my google searches always bring me those kind of non pertinent results).
Maybe RoboCopy (Robust File Copy) could do just that ? :cry:

This Rename preset will cut out the third level folder from the path of all selected files. Use the Preview to check if it really does want you want. The lines starting with DOpus.Output can be out-commented // which might increase performance.

function OnGetNewName(getNewNameData) {
    var tmpPath = String(getNewNameData.item.path);
    var tmpStem = getNewNameData.newname_stem;
    var tmpExt = getNewNameData.newname_ext;

    DOpus.Output(tmpPath + '\\' + tmpStem + tmpExt + ' --->');

    tmpPath = tmpPath.replace(/^(.:\\.*?\\.*?)(\\.*?)(\\.*|$)/, '$1$3');

    DOpus.Output(tmpPath + '\\' + tmpStem + tmpExt + '\n');

    return tmpPath + '\\' + tmpStem + tmpExt;
}

32564.orp (750 Bytes)

Careful son, you are walking on thin ice here, no blasphemy please :wink:

"Maybe RoboCopy (Robust File Copy) could do just that"
I'm sorry but I'm trying to find a solution, any solution :wink: So I look everywhere around and this was just me, not very cleverly you're right, sharing my thought and findings. I wasn't trying to be disrespectful or anything :wink:

Thanks lxp for such a quick answer.
1/ Sorry again, but I know nothing about scripts (I see JS, which means... java ?). And I don't know where I have to copy/paste that code. I know it's hard to imagine how much people know when trying to help :wink: To make it simple : I'm a 3D artist. I know a lot about polygons and textures. But basically nothing other than that.

2/ "of all selected files" I have tons and tons of those sub-sub folders that need their content moved up the tree. Does this mean I'd have, for each of them, to select the files manually then run that script ?

3/ "This Rename preset[...]" My aim is to move files. Nothing has to be renamed in the process.

I thought I could stay in the MainFolder, and while there, run a batch, a script, a javascript ? (I'm not even sure what's the proper word) and that it would take care of every files in all sub-sub folders and move them up the tree (to the sub-folder) without my having to select anything manually.

The JScript is for reference, no hard feelings if you ignore it :wink:

  • Copy the .orp into /dopusdata\Rename Presets.
  • Select all folders you need (maybe test with a small sample), can be anywhere you want
  • Open the Advanced Rename dialog and select the new preset
  • Check buttons like in my example
  • Hit F5 to generate the script preview

That sounds excellent. I'm trying right away and will tell you whether it worked.
Thanks a lot for spending that much of your time trying to help with that !
"maybe test with a small sample" That much was already done :wink: Thanks for the security advice.

Well, it's all very obscure to me. I read your code as slowly as I could, but it's like chinese to me.
BUT : you did an amazing job as always. This script works like a charm. I'd have never thought I'd "find" a solution that fast, if ever.
You really saved me hours and hours of copy/pasting files manually. I'll be sure to use those hours to work on my 3D modeling. Thanks to you.

I'm sorry you had to explain everything that clearly. Even how and where to load that .orp file. Hopefully this thread, your nice explanations and this miraculous piece of code will be useful to many more users than just myself.

:+1: Thanks Leo and Ixp.
I wish you a great day !

1 Like

I know, this is fairly old thread, but nonetheless I would like to thank you for this one.
So far I have been moving such files in 'misplaced' sub sub folders manually, PITA and boring.

This time something went wrong with some saving script and I ended up with over 50 folders to be 'handled'.

Like this
D:\Temp\TOL\Sub Folder Blah Blah\Sub Folder2\Sent Items\File Name XYZ1.jpg
D:\Temp\TOL\Sub Folder Blah Blah\Sub Folder2\Sent Items\File Name XYZ2.mp4
D:\Temp\TOL\Sub Folder Blah Blah\Sub Folder2\Sent Items\File Name XYZ3.psd

files to move up 3 'steps'
D:\Temp\TOL\Sub Folder Blah Blah\File Name XYZ1.jpg
D:\Temp\TOL\Sub Folder Blah Blah\File Name XYZ2.mp4
D:\Temp\TOL\Sub Folder Blah Blah\File Name XYZ3.psd

Your script helped me out a lot.

Just to say thanks!

1 Like