MannyLNJ
asked on
Mass moving of files into folders based on file name
I have a few thousand files that due to a poor attempt at orginization by myself were dumped into a single directory.
The file names are on the order of wwXXXX-YY-ZZZZZZZ-.ZIP where
ww is the same
XXXX is a four digit number
YY is a two digit number
zzzzz is a varible length descriptor.
I need the script to do
1) Make a directory called wwXXXX
2) Move everything that matches wwXXXX* to the just made directory
3) increase XXXX by 1
4) Repeat until everything is moved correctly.
I started writing a batch file where I could specify the wwXXXX but I realized it would take me a few days to do this by hand and there has to be an easier way
The .CMD script I am using is
mkdir no%1
cd no%1
dir ..\..\no%1-*.*
move ..\..\no%1-*.* .
cd ..
The file names are on the order of wwXXXX-YY-ZZZZZZZ-.ZIP where
ww is the same
XXXX is a four digit number
YY is a two digit number
zzzzz is a varible length descriptor.
I need the script to do
1) Make a directory called wwXXXX
2) Move everything that matches wwXXXX* to the just made directory
3) increase XXXX by 1
4) Repeat until everything is moved correctly.
I started writing a batch file where I could specify the wwXXXX but I realized it would take me a few days to do this by hand and there has to be an easier way
The .CMD script I am using is
mkdir no%1
cd no%1
dir ..\..\no%1-*.*
move ..\..\no%1-*.* .
cd ..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Looks good I just need to change it so instead of creating the directory with just the number that is count it uses the prefix plus the number do I change
if exist %prefix%%D%*.%ext% (
if not exist %D%\ md %D%&echo md %D%
xcopy /y %prefix%%D%*.%ext% %D%\
to
if exist %prefix%%D%*.%ext% (
if not exist %D%\ md %D%&echo md %prefix%%D%
xcopy /y %prefix%%D%*.%ext% %%prefix%D%\
if exist %prefix%%D%*.%ext% (
if not exist %D%\ md %D%&echo md %D%
xcopy /y %prefix%%D%*.%ext% %D%\
to
if exist %prefix%%D%*.%ext% (
if not exist %D%\ md %D%&echo md %prefix%%D%
xcopy /y %prefix%%D%*.%ext% %%prefix%D%\
Try this first (will only echo commands & won't copy anything):
if exist %prefix%%D%*.%ext% (
if not exist %prefix%%D%\ echo md %prefix%%D%&rem echo md %prefix%%D%
echo xcopy /y %prefix%%D%*.%ext% %prefix%%D%\
Then when you're happy with the copy commands you see, make it this:
if exist %prefix%%D%*.%ext% (
if not exist %prefix%%D%\ md %prefix%%D%&echo md %prefix%%D%
xcopy /y %prefix%%D%*.%ext% %prefix%%D%\
if exist %prefix%%D%*.%ext% (
if not exist %prefix%%D%\ echo md %prefix%%D%&rem echo md %prefix%%D%
echo xcopy /y %prefix%%D%*.%ext% %prefix%%D%\
Then when you're happy with the copy commands you see, make it this:
if exist %prefix%%D%*.%ext% (
if not exist %prefix%%D%\ md %prefix%%D%&echo md %prefix%%D%
xcopy /y %prefix%%D%*.%ext% %prefix%%D%\
ASKER