Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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!

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)

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.

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

![]() |
![]() |
![]() |

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