Printer Version Table of Contents Project Home Page
.FAQ.........: How can I rename a log file or a directory to a name containing today's date?
.DISCUSSION..:
This is certainly the most frequently asked question regarding Fdate.

Here are several examples of renaming a file and a directory, to a date that contains a 2-digit or 4-digit year.

Note that in the custom output format, lower-case "y" indicates a 2-digit year, and upper-case "Y" indicates a 4-digit year.

Note that the rename operation will fail if a file/directory with the old name cannot be found, or if a file/directory with the new name already exists. That means that if you attempt to run the same command more than once a day, it will fail on the second attempt to run it because a file (or directory) with the new name will already have been created when you ran it the first time.

Note that we TYPE (echo to the screen) junk.bat before calling it. That way, if it fails, we will be able to see the text of the command that failed.

For more information on the custom output format, see the entry for the "/C" parameter.

.EXAMPLE.....:
@echo off
:: rename file BACKUP.LOG to yymmdd.LOG (ex. 950508.LOG on May 8, 1995)
FDATE /Ff /C"~@rename backup.log ~y~M~D.log"> junk.bat
type junk.bat
call junk.bat
del  junk.bat

.EXAMPLE.....:
@echo off
:: rename file BACKUP.LOG to ccyymmdd.LOG (ex. 19950508.LOG on May 8, 1995)
FDATE /Ff /C"~@rename backup.log ~Y~M~D.log"> junk.bat
type junk.bat
call junk.bat
del  junk.bat

.EXAMPLE.....:
@echo off
:: rename directory BACKUP to yymmdd (ex. 950508 on May 8, 1995)
FDATE /Ff /C"~@rename backup ~y~M~D"> junk.bat
type junk.bat
call junk.bat
del  junk.bat

.EXAMPLE.....:
@echo off
:: rename directory BACKUP to ccyymmdd (ex. 19950508 on May 8, 1995)
FDATE /Ff /C"~@rename backup ~Y~M~D"> junk.bat
type junk.bat
call junk.bat
del  junk.bat