Jump to content

Save a file as "Date-Time" in DOS


Recommended Posts

I have a command line program that creates text/html files in a specific directory. The problem is that it will overwrite the old copies if i run it again without renaming the old copies. Is there a way to make DOS sve a file as the current date and time. The app's syntax is the following:

app.exe /shtml [filename].html

app.exe is the program of course, the /shtml tells it to save the file as html and the filename part is self explanatory. What can i do to make this save each file with a timestamped title?

Link to comment
Share on other sites

Welcome to the Windows Forum.

It depends if you have control over your application, i.e. if you are able to modify it.

If yes, just change it to append date & time to the filename.

If not, append the DATE and TIME environment variables to the filename in your line command, e.g.

app.exe /shtml [filename.%DATE%.%TIME%].html

P.S. see this article if you want to remove dashes, colons, etc. from the standard DATE/TIME environment variables

Link to comment
Share on other sites

Awesome. I didnt even think of checking wiki (my geek sense must be wearing thin, lol). I ended up doing this:

@echo off 
echo %DATE% %TIME%
set MTH=%DATE:~4,2%
set DAY=%DATE:~7,2%
set YR=%DATE:~12,4%
set HR=%TIME:~0,2%
set HR0=%TIME:~0,1%
if "%HR0%"==" " set HR=0%TIME:~1,1%
set MIN=%TIME:~3,2%
set SEC=%TIME:~6,2%
set MYDATE=%MTH%-%DAY%-%YR%-%HR%hr%MIN%m%SEC%s

start app.exe /shtml ff\%MYDATE%.html

which give me the output:

10-24-08-00hr39m27s.html

Could not be better, imo. Thanks a ton for the help, i really appreciate it!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy