Discussion Locked

File Naming

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How can a file be named with the current days date? (example: 061801.txt)

5 replies

by jim.schromm

Create a program which puts the date in the format you want. Have the program call a batch file and pass the filename as a parameter to the batch file.

by beermonster

Try putting this in a cmd file (this is for an NT system)-

rem - echo the date to a text file
date /t > c:\today.txt

rem strip the date out of the file and set a variable for it
for /F "tokens=2" %%A in (c:\today.txt) do set today=%%A
rem the next two lines are just to echo to the screen what its doing, you can strip these out
echo %today%
pause
rem in my date format, the components are separated with a / , this line strips that
rem out. If your date has a different separator (sometimes it's \) then edit the line accordingly)
set today=%today:/=%

rem the next two lines are just to echo to the screen what its doing, you can strip these out
echo %today%
pause

Now you can use the %today% variable to name the file

IE
echo hello >> %today%.txt
or
ren someotherfile.txt %today%.txt

Hope this goes ok...

by meikle

Thank you very much. Your answer worked perfectly. Of course I had to do some reading on scripting, as I am not a programmer/developer, but it looks as though that is an area in which I need to invest some study. Thanx again! meikle_r@hotmai.com

This discussion is closed to new replies.