Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to organize an external hard drive that contains thousands of files. The files are named such as:
00001-a.*
00001-b.*
00002-a.*
00003-a.*
00003-b.*
00003-c.*
etc....I would like to create folder for each of the file names up to the delimiter hyphen and then move all the associated files into that folder. In this case, 00001 a and b would be in a folder 00001 which was just created. 00002-a would be in folder 00002, etc. The files don't all have five digits in the first part of the file name, but they all seem to have the hyphen delimiter.
Overall, I think a script that would take the file name up to the hyphen, create a folder named after it, and then move every file with that name up to the hyphen regardless of what's after the hyphen in to the newly created folder is what I'm looking for. Does that make sense?
Any help would really be great!
Thanks!

Untested:
FOR /F "delims=-" %%a IN ('DIR /a-d /b') DO MD "%%a" 2>NULFOR %%a IN (*) DO FOR /F "delims=-" %%b IN ("%%a") DO MOVE "%%a" "%%b"

Thanks for the quick reply! I'm not quite sure how to implement this though. Could you break down what each part of the command does, or tell me where I could look it up?
Is /F the folder location?
Finally, do I just put this into the dos prompt?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |