Help with batch please

Gigabyte / P35c-ds3r
March 22, 2010 at 07:16:03
Specs: Microsoft Windows XP Professional, 3 GHz / 3582 MB

i was wondering if someone can help please, i have no experience with batch files, but if someone could possibly guide me that would be awesome.

I have about 300 folders at the root of my hard disk (J:/). Each folder contains one file.

I have managed to change all the names of the folders to how i want them to be.

What i need to do now is name the file within each folder the same as the folder name.

so for example i have a folder called 'Wedding 12/12/2008' and the file inside is called '0861258' i want to rename that file to exactly what the folder is called.

Any ideas how i can achieve this please?


See More: Help with batch please

Report •

March 22, 2010 at 07:31:04
Set your current directory as J:\ then issue

for /D %%j in (*) do @ren "%%j\*.* " "%%j"

As the statement is not tested I suggest you run it inserting an @echo. before the @ren to test. If you directly issue the command at prompt replace %%j with %j.

Report •

March 22, 2010 at 07:57:42
I like IVO's train of thought, but I don't like the results. That command will remove the file extension. (Perhaps "%%j.*" would be better?) Also, it doesn't work on sub directories.

Report •

March 22, 2010 at 08:07:15
You said your folders hold just one file, do not report the existence of subfolders. Neither you specified the files should retain the extension as guessed from your example.

The statement can be modified but now I have to leave. Later I will re-examine the issue. Always post *exactly* your working environment.

Report •

Related Solutions

March 22, 2010 at 08:29:59
IVO, I ain't AlwaysWillingToLearn. Another cup of coffee, perhaps?

Report •

March 22, 2010 at 08:43:05
Hi IVO, Razor,

thank you so much for your help, appreicate you creating and posting the solution for me. IVO you are correct there is only one file (.avi) in each folder, i have about 300 folders at the root of my j:/ drive and each folder only contains one avi file.

Razor you are correct I would like to retain the .avi extention if that is possible?

Also im intrigued, what does echo do? i have seen it a lot whilst searching for batch code..

Wow i cant believe such a small line to do what i am attempting that is so awesome.

Thanks for the help guys.

Report •

March 22, 2010 at 14:20:30
IVO, Razor2.3,

one word Amazing!!!!

you guys are awesome, i took in what you both had suggested and installed a test drive on which i created a few folders, subfolders and files and ran the batch to see what it done, and it worked absolutely as needed. Thank you both so much for your help this has saved me hours of work renaming the files, like i had done with the folders... Guys i appreciate the your help very much. Thanks :-)


Report •

March 22, 2010 at 20:28:22
FYI, it's usually a bad idea to use slashes in file or folder names.

It may not getcha today, but could jump up at the least convenient moment.

Helping others achieve escape felicity


Report •

Ask Question