Computing.Net > Forums > Windows XP > Create folders based on file names?

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Create folders based on file names?

Reply to Message Icon

Original Message
Name: blake (by ryo_ohki)
Date: September 8, 2006 at 11:06:24 Pacific
Subject: Create folders based on file names?
OS: WinXP
CPU/Ram: 2Ghz
Manufacturer/Model: Me
Comment:

Does any one know of a batch script that can create folders based on file names and then move those files into the folders? For example I have two files 990355-0001 and 990355-0002. I need to make a folder 990355 and move both of these files into it. I don't really know anything about creating batch scripts.


Report Offensive Message For Removal


Response Number 1
Name: Ed in Texas.
Date: September 9, 2006 at 00:23:54 Pacific
Reply:

blake, is this gonna be an on-going thing or just a one time deal? Unless it's on-goimg, why not simply create a new folder and name it the way you like and then drag/drop the desired files rather than bother with a script?
HTH.
Ed in Texas.


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: September 9, 2006 at 00:41:28 Pacific
Reply:

@echo off
for /f %%F in ('dir/b/a-d 9*.') do call :sub1 %%F
goto :eof

:sub1
set name=%1
md %name:~0,6%
move %* %name:~0,6%

====================
Note that you'll get errors because on secomd and succeeding loops on a given prefix the directory will already exist.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 3
Name: blake (by ryo_ohki)
Date: September 11, 2006 at 06:36:40 Pacific
Reply:

Ed in Texas, This is an on-going thing. I have several thousand files that I need to put in folders with similar file names.

Mechanix2Go, When I run the script I get a File Not Found error.


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: September 11, 2006 at 06:47:08 Pacific
Reply:

do this:

dir/b/a-d 9*.

and post a few lines of the result


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: blake (by ryo_ohki)
Date: September 12, 2006 at 14:47:39 Pacific
Reply:

Ok I figured it out. It was because I used the wrong file names so I removed the 9 from the script. Thanks for the script.

Here are the changes I made:

@echo off
REM This script creates folders based on file names and moves those files into the folders.

REM *.jpg is the search term. Change this to search for different files.

REM md %name:~0,6% will make a directory based on the first 6 characters of the file name. Change to 5% for the first 5 characters.

REM move %* %name:~0,6% will move the file to the directory based on the first 6 characters of the file name. Change to 5% for the first 5 characters.

for /f %%F in ('dir/b/a-d *.jpg') do call :sub1 %%F
goto :eof

:sub1
set name=%1
md %name:~0,6%
move %* %name:~0,6%


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home



Results for: Create folders based on file names?

Auto create folders from file dates
    Summary: Can anyone help me write a batch file that will run in Windows XP (DOS prompt) that will look at all the files in a folder and create new folders based on the dates of the files in that folder? Hope ...
www.computing.net/answers/windows-xp/auto-create-folders-from-file-dates/172497.html

Cannot stop Trojan.Startpage reacti
    Summary: Hi folks, I have a trojan called Trojan.Startpage and cannot get rid of it. I've tried: NortonAV (but my hopes weren't high as it doesn't seem to do much with trojans); CWShredder (which deletes a h...
www.computing.net/answers/windows-xp/cannot-stop-trojanstartpage-reacti/129010.html

Thumbnail view: Missing file names
    Summary: I created a normal new folder and put a bunch of JPGs in it. I don't know how or why, but now when I view them in either Thumbnail or Filmstrip view, all the file names don't show. They will show if I...
www.computing.net/answers/windows-xp/thumbnail-view-missing-file-names/120498.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History






Data Recovery Software