Computer Hope

Microsoft => Microsoft DOS => Topic started by: doogin on November 10, 2008, 10:50:48 AM

Title: HELP: move files into folders based on file prefix
Post by: doogin on November 10, 2008, 10:50:48 AM
I've got a directory of 7,000 images organized into 300 groups based on numerical prefixes in ONE FOLDER:

0001-file_a.jpg
0001-file_b.jpg
0001-file_c.jpg

0002-file_a.jpg

0003-file_a.jpg
0003-file_b.jpg

I need to get all these files into a folder structure based on their prefix i.e. all the 0001 jpg's into an 0001 folder

any ideas? MUCH APPRECIATED!!!!!!!!!!!

--- revision
I know the folders can be made/named quickly using any folder creating program, but curious if this can be done easily in dos also. Moving the files into the directories is the main obstacle. Thanks!
Title: Re: HELP: move files into folders based on file prefix
Post by: Sidewinder on November 10, 2008, 12:34:12 PM
This may help you out:

Code: [Select]
@echo off
setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%x in ('dir /b *.jpg') do (
set fldr=%%x
set fldr=!fldr:~0,4!
if not exist !fldr! md !fldr!
copy %%x !fldr!
)

Batch file should be run from same directory where the jpg files are. Note: as a precaution used copy instead of move. If you're satisfied with the results you can delete the jpg files with del *.jpg

Paths can be  added to the code as appropriate.  8)
Title: Re: HELP: move files into folders based on file prefix
Post by: doogin on November 10, 2008, 01:12:05 PM
THANK YOU THANK YOU THANK YOU

that was awesome.

All in total, you just saved me from manually organizing over 33,000 documents.