Monday 13 September 2010

Getting the time into a filename using a batch file

I'm repeatedly grabbing some data from an external device, and I want it stored locally under a suitable filename which includes the time for reference.


:loop
SET now=%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
grabdata.exe data%now%.bin

REM The line below forces a pause for two seconds. Very handy!
@ping 127.0.0.1 -n 2 -w 1000 > nul

goto loop


A quick work of warning - you may need to adjust the parameters of the date to match your location.
when I type at the command prompt
echo %date%
I get
13/09/2010
so be prepared to modify if you don't have DD/MM/YYYY format.




No comments:

Post a Comment