Batch file counter

August 20, 2009 at 22:02:27
Specs: Windows XP
I am renaming a bunch of .pdf files and I'm having a hard time adding a counter after renaming. Here is what I have so far for my batch file---

rename \Company\DM\MC\Backup\09_08_20\*.*pdf MC_%YY_MM_DD%.pdf

Because there are multiple .pdf files and I want them to include the current date it won't rename all of them (obviously because you can't have more than one file with the same name).

Any suggestions on how to add a counter after the current date when renaming?

See More: Batch file counter

Report •

August 21, 2009 at 00:22:48
Use a for loop instead.

set count=1
setlocal enabledelayedexpansion
for /f %%a in (\Company\DM\MC\Backup\09_08_20\*.pdf) do (
rename %%a MC_%YY_MM_DD%!count!.pdf
set /a count=!count!+1

Something like that

There are no stupid questions, just stupid people.

Report •

August 25, 2009 at 07:48:49
I have another question....let's say I didn't want to use a counter-- is there a way to just use the rename command?

such as:

rename \Company\DM\MC\Backup\09_08_20\*.*pdf MC_%YY_MM_DD%.pdf

Report •

Related Solutions

Ask Question