Printer Version Table of Contents Project Home Page
.EXAMPLE.....: 81 Rename a file name to a name that contains today's date
.CATEGORY....: examples
.DISCUSSION..:
A very common need is to change a file's name to a name that contains today's date. This is something that you might want to do if you are a system administrator, for example, and every night you run a backup utility that produces a log file called something like BACKUP.LOG. To keep a historical collection of these files, each night, you need to rename BACKUP.LOG to <TodaysDate>.LOG.

This is how to do it.

If you need to do this with a granularity down to the minute, see EXAMPLE 82 Rename a file to a name that contains today's time


If you need to store a date in a filename, but are really limited in the number of bytes available, see EXAMPLE 83 Rename a file to a name that contains today's date in only 3 bytes


.CODE........:
:: today's date (/At) in CCYYMMDD format into environment variable DATE1
FDATE /Ff /At /Occyymmdd /Vdate1
:: rename BACKUP.LOG to ccyymmdd.LOG (ex. 19950508.LOG on May 8, 1995)
REN BACKUP.LOG  %date1%.LOG
SET DATE1=