1

I am trying to write a batch file that copies all *.r02 files from subfolders and put them in the current folder and rename them to avoid overwriting. Not sure why the following code doesn't work?

@echo off

set Current_Dir = %cd%
For /r %%a in (*.r02) do (
       set /a "counter+=1"
       COPY "%%a" "%Current_Dir%\_%counter%"
)
Stephan
  • 53,940
  • 10
  • 58
  • 91
Nbl123
  • 47
  • 7
  • besides delayed expansion, you have another failure: `set Current_Dir = %cd%` sets a variable `%Current_Dir %`. Remove the spaces on both sides of the `=` – Stephan Dec 21 '17 at 13:37
  • …and besides that, why create an eleven character variable containing exactly the same value as an already existing two character variable? – Compo Dec 21 '17 at 13:43
  • Hi, thanks for your comments @Stephan. I changed the batch file accordingly and it still doesn't work. – Nbl123 Dec 29 '17 at 10:20
  • @echo off for /r %%a in (*.r02) do ( set a/ "counter+=1" COPY "%%a" "%cd%\_%counter%" ) – Nbl123 Dec 29 '17 at 10:22
  • All Sorted. the following link is helpful "https://www.experts-exchange.com/questions/23432479/How-to-increment-counter-variable-in-DOS-batch-file.html". Many thanks. – Nbl123 Dec 29 '17 at 11:15

0 Answers0