A common question is how to give files names based on date or time. This is most easily done by placing the date and/or time in the environment and working from there. If we had variables named TIME and DATE, we could rename a generic file like FILE.TXT to something like this: 07-07-1998_4-56-13-83P-FILE.TXT with a line like this (assuming the file name is being passed as %1): ren %1 "%date%_%time%-%1" Getting the date into the environment is easy. Here's an example I call SETDATE.BAT: ---------------------------------------- @echo off echo.|date|find "Current" >cu##ent.bat echo set date=%%4> current.bat call cu##ent.bat del cu??ent.bat > nul ---------------------------------------- Getting the time into the environment is just as easy. Unfortunately, the time has embedded colons in it, and colons aren't legal in file names. Periods are legal, but they limit how you can use the rename command. Removing periods and colons is an character at a time problem handled by misusing the CHOICE command. Here's my suggestion I call SETTIME.BAT for getting time into the environment: ---------------------------------------- @echo off echo.|time|find "Current" >cu##ent.bat echo set time=%%3> current.bat call cu##ent.bat :: At this point the time is in the environment but has :: colons and periods in it. Both are bad news. They :: will be replaced by harmless dashes. CU??ENT.BAT :: are no longer needed and will be overwritten below echo = | choice /c=%time%= cu##ent.bat > current.bat echo @echo off> cu##ent.bat echo set time=>> cu##ent.bat echo :LOOP>> cu##ent.bat echo shift>> cu##ent.bat echo if "%%1"=="]?" goto DONE>> cu##ent.bat echo if "%%1"==":" goto REPLACE>> cu##ent.bat echo if "%%1"=="." goto REPLACE>> cu##ent.bat echo goto KEEP>> cu##ent.bat echo :REPLACE>> cu##ent.bat echo set time=%%time%%->> cu##ent.bat echo goto LOOP>> cu##ent.bat echo :KEEP>> cu##ent.bat echo set time=%%time%%%%1>> cu##ent.bat echo goto LOOP>> cu##ent.bat echo :DONE>> cu##ent.bat call current.bat del cu??ent.bat > nul ---------------------------------------- Bad news if you live in the UK! The date command there includes slashes which aren't allowed in file names. What's worse, the method I use (using the CHOICE command) to remove colons from the TIME output won't work: CHOICE can't handle slashes. So here is SETDATE.BAT which will work in the US or UK, but insures the date separator is a dash: ---------------------------------------- @echo off echo.|date|find "Current" >cu##ent.bat echo set date=%%4> current.bat :: At this point cu##ent.bat contains a line like :: Current date is Wed 10-06-1999 :: in the US or :: Current date is Wed 06/10/1999 :: in the UK. But we must remove UK slashes! They :: always occur in the same place, so we use DEBUG :: to ensure they are harmless US style dashes. echo e 116 "-" > script echo e 119 "-" >> script echo w >> script echo q >> script type script | debug cu##ent.bat > nul del script > nul call cu##ent.bat ---------------------------------------- So as a final example, assume I have a program named PROCESS.BAT which produces a file named FILE.TXT. I run the PROCESS program several times a day, but each run overwrites the old FILE.TXT. To save the file, I must rename it with a unique name. I can do this by adding date and time to the filename: ---------------------------------------- call process.bat call setdate.bat call settime.bat ren file.txt "%date%_%time%-file.txt" set time= set date= ---------------------------------------- Now instead of running my PROCESS.BAT, I run the code shown above. Notice I use dashes to separate the time, date, and file name. Even though there are no spaces in the example I used, I still put quotes around the name. I shouldn't have to, but sometimes the REN command can be picky. Always quote file names to be on the safe side! CAUTION: All the above code (like virtually all my code) is for Win9x. If you use NT, please go to this page: http://www.calweb.com/~webspace/batch/nt/index.htm and look for the links telling you how to set the date into the environment. Alternatively, if you installed scripting (it came out with NT SP4), go to this page: http://www.calweb.com/~webspace/scripting/index.htm and look for the links to "DateName.vbs" and "TimeDateName.vbs" near the bottom of the page. http://www.calweb.com/~webspace