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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Create folders based on file names?

Reply to Message Icon

Name: blake (by ryo_ohki)
Date: September 8, 2006 at 11:06:24 Pacific
OS: WinXP
CPU/Ram: 2Ghz
Product: 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.



Sponsored Link
Ads by Google

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.


0

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



0

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.


0

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



0

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%


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






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


Sponsored links

Ads by Google


Results for: Create folders based on file names?

Auto create folders from file dates www.computing.net/answers/windows-xp/auto-create-folders-from-file-dates/172497.html

Copy files into a new directory based on file www.computing.net/answers/windows-xp/copy-files-into-a-new-directory-based-on-file/179010.html

Cannot stop Trojan.Startpage reacti www.computing.net/answers/windows-xp/cannot-stop-trojanstartpage-reacti/129010.html