1.

Solve : File organizing problem?

Answer»

Hey everyone.

I have a bunch of files that i need to organize in folders that fits their name. Example:

..\file A_part1.txt
..\file A_part2.txt
..\file A_part3.txt
..\file B_part1.txt
..\file B_part2.txt
..\file C.txt

this NEEDS to become:

..\file A\file A_part1.txt
..\file A\file A_part2.txt
..\file A\file A_part3.txt
..\file B\file B_part1.txt
..\file B\file B_part2.txt
..\file C\file C.txt

As you can see in the example, the file part names are all seperated from the actual filename with underscore "_". This might help a batch file RECOGNIZE what the folder name should be.

Any help would be greatly appreciated thanksExcept for File C which does not have an underscore. So we would need to see all examples of your file names to be certain we are coding for everything possible.Of cause.
Heres a few real examples:
"1984 - speech_part1.txt"
"FN. 1988 - sabb.txt"
"Ttt88.txt"

That should cover it. only the files that are in parts, needs to be grouped in the same folder. Quote from: mthmobu


That should cover it. only the files that are in parts, needs to be grouped in the same folder.
So the example in your first post was incorrect regarding file C and we can in theory just look for files ending in _Part*.txt?Hehe yes but the files that isent in parts, still needs to go into its own folder as well.Clear as mud...Untested as I am POSTING from my phone.
Code: [Select]for /f "tokens=1* delims=_" %%G in ('dir /a-d /b *_part*.txt') do (
     mkdir "%%~G" 2>nul
     move "%%~G_%%~H" "%%~G"
)That was beautiful it worked PERFECTLY, i had over 20.000 files that needed sorting.
All the part files are now grouped perfectly, and the folder names are all correct.
You saved me Alot of WORK, thank you very much


Discussion

No Comment Found