I have about 15k files in a flat folder. All are named something like blah blah - whatever.png
. Basically, I'd like to move them all into folders named blah blah
. I don't want to rename any of them, just bump them into their respective folders. I imagine I need to do this with some kind of regex, but I can't seem to workout how to apply regex in this context.
Answer
The for
command does not support regular expressions.
Assuming all files contain a -
character, you could probably use this code in a batch file:
for /f "delims=- tokens=1* usebackq" %%a in (`dir /b *.png`) do (
if not exist "%%a" mkdir "%%a"
move "%%a-%%b" "%%a"
)
delims=-
will split the filenames on -
, giving you the directory name which will be created if it doesn't exist yet. Next, the original filename, %%a-%%b
, will be moved to that directory.
No comments:
Post a Comment