Computing.Net > Forums > Programming > Batch file counter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file counter

Reply to Message Icon

Name: netwgirl
Date: August 20, 2009 at 22:02:27 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: xterm11
Date: August 21, 2009 at 00:22:48 Pacific
Reply:

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.


0

Response Number 2
Name: netwgirl
Date: August 25, 2009 at 07:48:49 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file counter

Batch File Counter Increment www.computing.net/answers/programming/batch-file-counter-increment/16956.html

Need batch file to delete old files www.computing.net/answers/programming/need-batch-file-to-delete-old-files/14092.html

Batch file - count www.computing.net/answers/programming/batch-file-count/11855.html