2
0
I have been trying all morning to try to write a simple batch rename script. This is my first time trying this sort of thing. I have been trying to use For /R
so that my command recurses through subfolders but it is not working.
My code looks like this:
FOR /R %%a in (.) do REN "i.JPG" "inlet.JPG"
REN
is working in the parent directory, but not recursing through subdirectories. Can anyone see what I am doing wrong?
Thank you.
You need to add the
/d
option infor
if you want to match directories. Also, you need to use"%%a\i.JPG"
in theren
command source file name. – AFH – 2018-01-05T19:02:08.920Thank you. I fixed the filename and added the
%%a
. This seemed to solve the problem. What do you mean match directories? – eyerah – 2018-01-05T19:06:13.690By default
for
matches files, not directories, unless you add/d
: seefor /?
for more details. – AFH – 2018-01-05T19:08:19.843Further investigation shows that
.
will be matched without/d
- I don't fully understand why. What%%a\i.JPG
expands to isSubDirName\.\i.JPG
. A neater solution isFOR /R %%a in (i.JPG) do REN "%%a" "inlet.JPG"
: this avoids errors on subdirectories with noi.JPG
file in them, especially if you want to rerun the batch file. – AFH – 2018-01-05T19:23:58.230@eyerah Can you specify what you really want to do with batch file? Is there only a single file or many file with same name? – Biswapriyo – 2018-01-05T21:25:49.183
I've always linked using the
FOR /F
and then putting theDIR /S
commands to do theREN
commands if doing so recursively—just a personal preference I suppose but always works very well for me. – Pimp Juice IT – 2018-01-06T01:10:46.743Thanks all for the thoughtful comments and welcoming vibes. @Biswapriyo
I just wanted a script to rename photos that I had previously sorted through and added simple codes (i.e., "i"). In sub directory there were many files, but no files with the same name twice. – eyerah – 2018-01-11T01:09:56.703