1.

Solve : Renaming with Unique Name?

Answer»

Our shop is standardized on WIN2K. I've been tasked to write a batch file that will archive a given file to a specific directory each day at a specific time. Seems EASY using win2k "schedule task" executing a DOS batch file with REN or RENAME, but how do I assure that the archived file name is unique each time the batch file is run. Can I somehow append a timestamp to the name each time?You can insert the date and time into a filename using the %date% and %time% environment variables.

Ex: REN c:\path\filetobackup.ext "file %date% %time%.ext"
thank you for the suggestion. Please VERIFY then, I have a directory named TEST and a file named testfile.txt in that directory. The statement...

REN TEST\testfile.txt TEST\testfile %date%.txt

...should create a file in TEST named testfile20050113.txt

Use "quotes" for non-8.3 filename or path specs.

REN TEST\testfile.txt "TEST\testfile%date%.txt"

Also, this assumes you use a country= statement with a country code specifying valid DOS naming characters in the date. Forward slash (a commonly used date separator) won't work, but yyyy.mmdd or dd-mm-yyyy will. Search 'country codes' for spec and use it in the CONFIG.SYS or International FUNCTIONS of the OS.



Discussion

No Comment Found