Batch move a folder's content up one level
This is not very sophisticated, and I am sure people will come up with better solutions, but here is a quick one:
- Do a simple (Explorer) search for
*
, starting in the folder where you want to move the stuff to. It might take half a minute or so to complete. - Sort the result by path
- Select all the files (which is what you want to move) that are not already in the target folder (those would be your existing 'thousands of directories'. They will be all together after the sort, so 'click' and 'shift+click' does it.
- Drag them into the folder structure tree on the left and drop them into the target folder.
- Get a coffee or do some other work while it moves. Windows can typically move 40 - 7000 files per second, depending on your hardware.
- Select all the - now empty- directories and delete them.
Note that you can also do step 1 with filters if you want only certain file types, for example *.jpg,*.png
.
This should work for you:
for /r %i in ("images\*.*") do move %i %~pi..
%~pi
extracts the path from%i
(ending with\
)..
placed after the above path points to the parent directory
Of course it doesn't handle the situation where you have files with conflicting names in subdirectories.
Batch move a folder's content up one level
Here's a batch solution where the MoveFromDir is the directory you start with for the contents within it you will move, and the MoveToDir is the directory explicit path those contents will be moved up one level from the MoveFromDir, so you'd have to set these variables accordingly.
Move all folders and files in MoveFromDir and beneath to MoveToDir
Please note that running only the second FOR loop of:
FOR /F "TOKENS=*" %%A IN ('DIR /S /B "%MoveFromDir%\*.jpg"')
You can specify just the file extensions you want to move to the MoveToDir (e.g. jpg)
@ECHO ON
SET MoveToDir=C:\Photos\subject\randomnumbers
SET MoveFromDir=C:\Photos\subject\randomnumbers\images
:: Move the folders from the move directory to the move to directory
FOR /D %%A IN ("%MoveFromDir%\*") DO MOVE /Y "%%~A" "%MoveToDir%"
:: Move any remaining files (or folders) from the move directory to the move to directory
FOR /F "TOKENS=*" %%A IN ('DIR /S /B "%MoveFromDir%\*.*"') DO MOVE /Y "%%~A" "%MoveToDir%\"
GOTO EOF
Further Resources
- FOR /F
- FOR /D
- MOVE