Computing.Net > Forums > Programming > Make new folder from file name

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.

Make new folder from file name

Reply to Message Icon

Name: YACOLT
Date: February 2, 2008 at 21:50:01 Pacific
OS: xp pro
CPU/Ram: not sure
Product: not sure
Comment:

I would like to take every file name in a folder - make a new sub-folder inside that folder naming it from each file name - and then put the file in the folder that has been named after the file.

I spent over an hour on this site looking through past posts to see if I could find something I could modify - but I’m not much of a programmer. I did see stuff that was similar but I’m not even sure if I would use a batch file or DOS commands to do what I need to do.

I’m using XP professional and I saw some code that used XP to do stuff.

Could someone point me to the best way to do this?

Thanks a lot!



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: February 3, 2008 at 02:25:02 Pacific
Reply:

If you want to run a batch, save the following code

@Echo Off
For %%J in (%1\*.*) Do (
MD %%~dpnJ
move %%J %%~dpnJ)

and at prompt type

MyBatch Your_Folder

or if you want to type just one command at prompt

For %J in (Your_Folder\*.*) Do @(MD %~dpnJ & move %J %~dpnJ)


0

Response Number 2
Name: klint
Date: February 3, 2008 at 06:40:00 Pacific
Reply:

It's not quite as easy as it seems. Do you want the directory name to have the same extension as the file name? If so, you can't create a directory of the same name as an existing file name, so you'll have to create a directory with a temporary name first, then move the file into the temporary directory and finally rename the directory to the name of the file.

Even if you want to name the directory without an extension, you will still have to use a temporary name because some files may have no extension and you won't be able to create directories for them.

Now there's another problem: what name do you use as a temporary name that you can guarantee it will never clash with an existing file name?

So... easy problem, tricky solution.


0

Response Number 3
Name: Mechanix2Go
Date: February 4, 2008 at 02:47:22 Pacific
Reply:

Hard tellin' why anybody would want a dir name like my.xls but if so, just increment the temp names.


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

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Make new folder from file name

Copy folders, rename file if name duplicated www.computing.net/answers/programming/copy-folders-rename-file-if-name-duplicated/19716.html

Append new text onto file name and copy www.computing.net/answers/programming/append-new-text-onto-file-name-and-copy/19924.html

Make directories from file name and move file www.computing.net/answers/programming/make-directories-from-file-name-and-move-file/19988.html