batch file to rename files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

batch file to rename files

#1 Post by daviddc114 » 17 Sep 2013 06:18

i have a directory "C:\Main" and within the directory several others "C:\Main\1" C:\Main\2" ect.. In each numbered directory there are 2 image files. Each directory structure is the same, meaning there in only 1 directory and always only 2 images in each. Can i make a batch file to go into "C:\Main" and rename all images in sub directories"1" "2" "3" ect.. to 0 and 1. so i want to end up with
C:\Main\1\0.png
C:\Main\1\1.png
C:\Main\2\0.png
C:\Main\2\1.png
C:\Main\3\0.png
C:\Main\3\1.png

ect ect..

is this possible?? thanks..

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

Re: batch file to rename files

#2 Post by foxidrive » 17 Sep 2013 07:06

What are the files called now?

Does it matter in which order they are renamed - if the filenames aren't constants?

daviddc114
Posts: 19
Joined: 23 Jul 2013 12:45

Re: batch file to rename files

#3 Post by daviddc114 » 17 Sep 2013 11:08

no, the 2 images within each folder are exactly the same. i just need 2 copies of the same image, so it doesn't matter which one is 0 or which one is 1.

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

Re: batch file to rename files

#4 Post by foxidrive » 17 Sep 2013 22:01

Code: Select all

@echo off
for /d /r "C:\Main" %%a in (*) do (
pushd "%%a"
   for %%b in (*.png) do (
      if not exist 0.png ren "%%b" 0.png
      if not exist 1.png ren "%%b" 1.png
   )
popd
)

Post Reply