Automatically make directories and move files into them
Posted: 11 Apr 2010 13:13
Everyone,
I have searched through this very helpful forum but haven't yet found the info I need.
I have a folder filled with 1,000-2,000 picture files. The file names are all in the format AAAA-BBB.ext where AAAA is a four-digit number (like 0602, 0513, 0845, etc.) BBB is a two- or three-digit number (12, 01, 003, etc.) and ext is tiff, jpg, psd, etc.
I am trying to write a batch script that will look at each file AAAA-BBB.ext and move it to a directory called AAAA (making that directory if it doesn't already exist), regardless of what BBB or ext are.
For example -- 0617-12.jpg would get moved to directory 0617/
0803-008.psd would get moved to directory 0803/
etc.
I am a newbie with batch scripts and have tried to begin at least by writing a batch script to make a series of directories, e.g. 0701, 0702, 0703, ... up to 0736. To do this, I wrote the following (I am using a console window in Windows Vista Home Premium):
When I execute this script, what it does instead is make a series of directories called 449, 450, 451, ... up to 478. Very strange! I suspect it has something to do with my leading zeroes.
Any ideas how to handle this? Or is there a quick script someone can point me to that will automate the entire task?
Thanks very much!
I have searched through this very helpful forum but haven't yet found the info I need.
I have a folder filled with 1,000-2,000 picture files. The file names are all in the format AAAA-BBB.ext where AAAA is a four-digit number (like 0602, 0513, 0845, etc.) BBB is a two- or three-digit number (12, 01, 003, etc.) and ext is tiff, jpg, psd, etc.
I am trying to write a batch script that will look at each file AAAA-BBB.ext and move it to a directory called AAAA (making that directory if it doesn't already exist), regardless of what BBB or ext are.
For example -- 0617-12.jpg would get moved to directory 0617/
0803-008.psd would get moved to directory 0803/
etc.
I am a newbie with batch scripts and have tried to begin at least by writing a batch script to make a series of directories, e.g. 0701, 0702, 0703, ... up to 0736. To do this, I wrote the following (I am using a console window in Windows Vista Home Premium):
Code: Select all
SETLOCAL ENABLEEXTENSIONS
for /L %%G in (0701,1,0736) DO mkdir %%G
When I execute this script, what it does instead is make a series of directories called 449, 450, 451, ... up to 478. Very strange! I suspect it has something to do with my leading zeroes.
Any ideas how to handle this? Or is there a quick script someone can point me to that will automate the entire task?
Thanks very much!