Let’s consider a complex folder/files structure:
where recup_dir.[1 to infinity] are subfolders of recup_dir.
This folder structure is generated by PhotoRec, used to recover lost files from damaged/formatted/erased drives. The recovery process will generate a vast amount of recup_dir.X folders with a vast amount of recovered files in each of those folders.
I needed to move all the files found in those (very numerous 1 to infinity) subfolders into different folders based on the file extensions (so in each folder I would only have one filetype, making it a lot easer to browse through and extract important files out of the piles and piles of bulk information).
This would have been a very repetitive time consuming task to perform manually. Thankfully, Windows supports quite a bit of scripting in its Command Interpreter (CMD).
First step is to move all the files from each recup_dir.X subfolder to the parent recup_dir folder (so we can sort them later). Running
for /r %i in (*) do @move "%i" .
via CMD within the recup_dir will automatically perform this action.
Moving on, I needed to sort that huge amount of files (over one million at this particular task) to separate (automatically generated) subfolders based on their extensions.
For this task, I created a sort.bat file outside the recup_dir folder (so it doesn’t auto-sort itself) with the following content:
for %%i in (*.*) do (
echo Attempting to create folder '%%~xi'...
echo Moving file %%i to %%~xi\%%i
move %%i %%~xi\%%i
Calling sort.bat via CMD from recup_dir‘s parent folder will process, sort and move all the files to their (automatically created) subfolders based on their extensions.
Thank you so much. I was going crazy trying to sort them out manually.
You are amazing, thank you for this!