Link to home
Start Free TrialLog in
Avatar of MannyLNJ
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 ..


ASKER CERTIFIED SOLUTION
Avatar of callrs
callrs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MannyLNJ
MannyLNJ

ASKER

Thanks. I'll give that script a shot. If I save it as fixit.bat  I should just type fixit when I cd into the directory my files are in correct?
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%\
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%\