Rename files... for Noob

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Rename files... for Noob

#1 Post by jeff p » 15 Apr 2012 01:18

Hello

I have about 75 folders. Each folder contains 30-40 unique .obj files. These files are named the same in each folder

ie:
1.obj, 2.obj, 3.obj,.... through 40.obj

Is it possible to create a script that will allow me to designate a unique name for each .obj file?

as an example, from here:
D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\Folder_01

1.obj renamed to V_GBH.obj
2.obj renamed to B_GGHC.obj
3.obj renamed to M_DFV.obj

etc.

Any help would be greatly appreciated

Thanks!

Jeff

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename files... for Noob

#2 Post by foxidrive » 15 Apr 2012 02:15

You can use a random number.

Or, if you want every folder to have unique names, start at 0001.obj and increment to 0040.obj and the next folder starts 0041.obj

Ir do you have the names in a text file that you want to use?

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Rename files... for Noob

#3 Post by !k » 15 Apr 2012 02:47

if new name from foldername is suit

Code: Select all

@echo off &setlocal enabledelayedexpansion

set "Parent=D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\"

for /f "delims=" %%f in ('dir /b/s "%Parent%\??.obj"') do (
   for %%r in ("%%~dpf.") do echo ren "%%f" "%%~nxr__%%~nxf"
)
pause

remove "echo" before "ren"

jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Re: Rename files... for Noob

#4 Post by jeff p » 15 Apr 2012 03:10

Thanks for the replies!

Expert, I'm not certain how to apply this code? Where do I indicate the new names list?


What i'm looking for is a code that does something like this:

In this folder D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\Folder_01

replace the name "1".obj with this " new name entered".obj
replace the name "2".obj with this " new name entered".obj
replace the name "3".obj with this " new name entered".obj
...
replace the name "40".obj with this " new name entered".obj

etc.


If possible a script whereby I indicate each old and new name

I will have to manually type the names within the code.
and then I can run the script for the remaining 74 folders (since they will all be the same naming convention).. I would only need to change the directory folder path for each one of those.

I hope this helps

Thanks again for any help on this.

jeff

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Rename files... for Noob

#5 Post by !k » 15 Apr 2012 03:18

run it once. it show new names in the tails, like

Code: Select all

ren "D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\Folder_01\1.obj" "Folder_01__1.obj"
ren "D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\Folder_01\2.obj" "Folder_01__2.obj"
...
ren "D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\Folder_74\39.obj" "Folder_74__39.obj"
ren "D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\Folder_74\40.obj" "Folder_74__40.obj"

if it's OK, remove "echo" and run it again

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename files... for Noob

#6 Post by foxidrive » 15 Apr 2012 03:27

This is easier in your case. Fill in the blanks in a text editor, save it as c:\a.bat and run the batch file below it.

This assumes that you want to name each file in a certain way.

It is designed to run c:\a.bat in every folder under D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\

Code: Select all

@echo off
ren 1.obj V_GBH.obj
ren 2.obj B_GGHC.obj
ren 3.obj M_DFV.obj
ren 4.obj .obj
ren 5.obj .obj
ren 6.obj .obj
ren 7.obj .obj
ren 8.obj .obj
ren 9.obj .obj
ren 10.obj .obj
ren 11.obj .obj
ren 12.obj .obj
ren 13.obj .obj
ren 14.obj .obj
ren 15.obj .obj
ren 16.obj .obj
ren 17.obj .obj
ren 18.obj .obj
ren 19.obj .obj
ren 20.obj .obj
ren 21.obj .obj
ren 22.obj .obj
ren 23.obj .obj
ren 24.obj .obj
ren 25.obj .obj
ren 26.obj .obj
ren 27.obj .obj
ren 28.obj .obj
ren 29.obj .obj
ren 30.obj .obj
ren 31.obj .obj
ren 32.obj .obj
ren 33.obj .obj
ren 34.obj .obj
ren 35.obj .obj
ren 36.obj .obj
ren 37.obj .obj
ren 38.obj .obj
ren 39.obj .obj
ren 40.obj .obj


To run it in all the folders (untested)

Code: Select all

@echo off 
pushd "D:\SVD_Tests\3D_Scenes\Characters\3D_Models\Export_Tests\"
for /f "delims=" %%a in ('dir /ad /b') do (
pushd "%%a"
call "c:\a.bat"
popd
)
popd

jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Re: Rename files... for Noob

#7 Post by jeff p » 15 Apr 2012 04:17

Thanks for all the help guys!

Foxidrive, your script worked exactly As i had hoped!

Many, many thanks!!!

Jeff

Post Reply