DOS: create filename based on date? [Closed]

- - Latest reply: ebley
Posts
1
Registration date
Saturday January 19, 2013
Status
Member
Last seen
January 19, 2013
- Jan 19, 2013 at 02:32 AM
Hello,

I need to be able to automatically generate a DOS .txt filename that is the 'date' of when it is created.

Any ideas? My DOS is rather rusty and have run out of ideas.
See more 

7 replies

Best answer
24
Thank you
You might try something like this...


set filea=MyBigFile%date:~10%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%.sav
copy MyData.dat %filea%

Since the date is Thu 07/30/2009 and the time is 14:07:00.00,
For today this would give a file named
MyBigFile200907301407.sav

good luck

Say "Thank you" 24

A few words of thanks would be greatly appreciated. Add comment

CCM 5633 users have said thank you to us this month

10
Thank you
copy nul %date:~10%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%.txt
6
Thank you
Sorry, that won't work from a batch file! If you don't mind what is in the file then this will work:

echo >%DATE%.txt

And if a zero-length file is important to you then create one manually as described before, then use:

copy yourZeroLengthFile %DATE%.txt
4
Thank you
Try this:

copy con %DATE%.txt

the press Ctrl-Z.

This will create a zero-length file named 24-Jul-2009.txt (or whatever).
4
Thank you
You might try something like this...


set filea=MyBigFile%date:~10%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%.sav
copy MyData.dat %filea%

Since the date is Thu 07/30/2009 and the time is 14:07:00.00,
For today this would give a file named
MyBigFile200907301407.sav

good luck
Posts
25
Registration date
Saturday November 7, 2009
Status
Member
Last seen
July 18, 2012
14
4
Thank you
It is better to use biterscripting for these kinds of things. DOS only has a subset of biterscripting commands.

This simple command will create the file <timestamp>.txt.

echo > { echo (gettime()+".txt") }
Posts
1
Registration date
Saturday January 19, 2013
Status
Member
Last seen
January 19, 2013
4
Thank you
Small Business Server is NOT R2 - so you have to schedule it with a bat file.

Here is a script inspired by this page. I put it as a scheduled task. It writes to a log file, then does the backup to that log file and makes an end to the log.

It adds a time stamp to each backup.

rem
rem
rem get the date and time without the slashes and colons. Note if I echo date and echo time I get dd/mm/yyyy and time is hh:ss:mm.ms
set filea=%date:~6,4%-%date:~3,2%-%date:~0,2%_%time:~1,1%%time:~3,2%%time:~6,2%
rem now start the log file
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> E:\GeekCentral\scripts\results\backuplog_%filea%.log
echo %date% %time% %username% start >> E:\GeekCentral\scripts\results\backuplog_%filea%.log
rem
rem - make a place to put the new backups
rem - note that I have a drive mapped to a shared folder "GeekCentral" so if I went to \\sbs-server\GeekCentral I have a folder there
rem that has the drive mapped here - and to my f: disk.
rem - see http://technet.microsoft.com/en-us/library/cc753321.aspx
mkdir "e:\GeekCEntral\BackupMount\Backup_%filea%"
rem
rem - now start the backup - see http://technet.microsoft.com/en-us/library/cc742083(v=ws.10).aspx and
rem webpage http://social.technet.microsoft.com/Forums/en-US/windowsbackup/thread/1ab34447-4e81-4589-8aa1-8275cff132fc/
rem
Wbadmin start backup -backupTarget:\\sbs-server\geekcentral\BackupMount\Backup_%filea% -include:C:,E: -vssFull -quiet >>E:\GeekCentral\scripts\results\backuplog_%filea%.log
rem
rem - end the log file
echo %date% %time% %username% end >> E:\GeekCentral\scripts\results\backuplog_%filea%.log
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ end >> E:\GeekCentral\scripts\results\backuplog_%filea%.log