0

I have this code with works great if the .bat is located in the same folder as the files. Code came from: .bat for batch rename to increment numbers in fname

@echo off
setlocal enabledelayedexpansion
set /a count=0
for /f "tokens=*" %%a in ('dir /b /od *.cbr') do (
 echo ren "%%a" !count!.cbr
 set /a count+=1
)

I would like to specificity a directory where the above process can take place.

This is my code but I cannot get it to work.

%NewFolder% - it is specified in the code above this part. 

   setlocal enabledelayedexpansion
set /a count=0
for /f "tokens=*" %%a in ('dir /b /od "004 - Images Ready\%NewFolder%\"*.JPG') do (
 ren "004 - Images Ready\%NewFolder%\%%a" "004 - Images Ready\%NewFolder%\"!count!.JPG
 set /a count+=1
)
Arthor
  • 666
  • 2
  • 13
  • 40
  • 2
    The help for `ren` states that "you cannot specify a new drive or path for your destination file", and by that it means the destination name is limited to just the base filename, e.g. `!count!.JPG`. – Eryk Sun May 28 '17 at 19:12
  • @eryksun Oh dear... Hmmm.. What would be a possible solution. I have the bat file located outside of the folder where I would like the process to take place. Thanks – Arthor May 28 '17 at 19:15
  • 2
    It looks like you want `ren "004 - Images Ready\%NewFolder%\%%a" !count!.JPG`. No? – Eryk Sun May 28 '17 at 19:19
  • @eryksun That is where all the files are. Yes. Thank you. The process is just to rename all the files in a directory and increment by 1. The bat would not be located in the same directory. – Arthor May 28 '17 at 19:21
  • `pushd "004 - Images Ready\%NewFolder%\"` before the `for` loop and remove all the directory stuff from the `for` loop. `popd` after the `for` loop – DavidPostill May 28 '17 at 19:50
  • @eryksun, you may want to post your comments as an answer, so the OP could accept it... – aschipfl May 29 '17 at 06:48
  • @eryksun Of course. I am still working on it. Thank you. – Arthor May 30 '17 at 12:57

0 Answers0