Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS-DOS Batch - renaming a file with previous EOM date 1

Status
Not open for further replies.

lmohr79

Technical User
Jan 18, 2005
39
US
I'm trying to write a simple .bat job that will rename a certain file from "file-20060713.txt" (created with today's date in a 3rd party software) as "file-20060630.txt" (the last day of the previous month).

I have used this script in previous .bat jobs to name files with the current date:

Code:
@echo off
for /f "tokens=2 delims= " %%A in ('date/T') do (
set date=%%A)
for /f "tokens=1-3 delims=/" %%A in ('echo %date%') do (
set m=%%A
set d=%%B
set y=%%C)

ren "C:\My Files\file.txt" %y%%m%%d%.txt

The resulting file name if run today would be 20060713.txt

I've tried to find commands that would set this to 063006.txt but am coming up empty.

I'd be running this on a WinXP Profession box.

Thanks for any help!
 
You cannot do this natively in Batch. I would suggest using VBScript which is already installed on an XP box.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks for the response - I'll work this up in VBScript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top