Operating System - Microsoft
1748269 Members
3435 Online
108760 Solutions
New Discussion юеВ

Re: Adding date to a filename

 
SOLVED
Go to solution
TheJuiceman
Super Advisor

Adding date to a filename

In DOS, how do you make a copy of a file and add the current date to the filename? Something like this....

copy file.bat file..bat

Thanks
9 REPLIES 9
Jon Finley
Honored Contributor

Re: Adding date to a filename

Can't be done using built-in tools...

Try using the XSET utility from http://xset.tripod.com

rem DATEFILE.bat
rem Makes a Text File with the Current Date as the Name

C:\BATCH\DOS\XSET CUR-DATE DATE YY-MM-DD
REM > %CUR-DATE%.TXT


This will make a zero-byte file which name will be in the format
of "Year-Month-Day". That keeps similar files in chronological order.
You may then load it into an editor and add text.

Jon
"Do or do not. There is no try!" - Yoda
Sanjay Kumar Suri
Honored Contributor
Solution

Re: Adding date to a filename

Hello

Following will work
set dd=%date:~0,2%
set mm=%date:~3,2%
set yy=%date:~6,4%
copy file.bat file.%dd%%mm%%yy%.bat

Sanjay Suri
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Sanjay Kumar Suri
Honored Contributor

Re: Adding date to a filename

Without set following command is also working.

copy file.bat file.%date:~0,2%%date:~3,2%%date:~6,4%.bat

Thanks.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Jon Finley
Honored Contributor

Re: Adding date to a filename

You tried this in DOS?

Not the NT/2000/XP command prompt, but under Win 98/95 (7.0) DOS or 6.22 MS-DOS?

Jon
"Do or do not. There is no try!" - Yoda
Jon Finley
Honored Contributor

Re: Adding date to a filename

Bobby... maybe I'm miss-reading your question. I understood you to ask how to do it under DOS. If you're asking how to do this within the CMD prompt of NT/2000/XP, then Sanjay has answered your question. In addition, there are several other postings in the MS forums across the last 2 years that discribe various other ways of creating a filename timestamp under NT/2000/XP.

Let us know what DOS version or OS you REALLY want to work this in.

Jon
"Do or do not. There is no try!" - Yoda
TheJuiceman
Super Advisor

Re: Adding date to a filename

Thanks everyone for the responses. What Sanjay suggested worked PERFECTLY!!! Thanks again for all of the help, guys!!! This forum is incredible!!!
Sanjay Kumar Suri
Honored Contributor

Re: Adding date to a filename

Hello Bobby

I am glad my solution worked for you.
Apart from appreciation, your libral allocation of points to my answer will help me inch towards my first cap.

Thanks.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Melis Bilsel
New Member

Re: Adding date to a filename

what if i also want to hour minute information in my filename like :file28022008114501
(fileddmmyyyyhh24miss)
any help would be appreciated
Jon Finley
Honored Contributor

Re: Adding date to a filename

Use the %time% variable along with the formatting options from above.

Jon
"Do or do not. There is no try!" - Yoda