Writing a batchfile capable of referencing a file who's name is the current date?

Soldato
Joined
21 Oct 2002
Posts
3,008
Location
At home of course :p
Writing a batchfile capable of referencing a file whose name is the current date?

Hi there. Tricky one this. I have a server which is generating log files in the format "ex<DateInReverse>.log"

For example today's file (06/06/07) is called ex070606.log

Yesterday's (05/06/07) is ex070605.log

Now how can I write a batchfile capable of referencing that filename?

For example how could I rewrite the command;

copy ex070606.log c:

to a command that will always copy today's log file when run?
 
Last edited:
batch files are great :).

Code:
@echo off

for /F "delims=/ tokens=1,2,3" %%i in ("%DATE%") do SET BLAH=%%k%%j%%i

SET FILE_NAME=ex%BLAH:~2%.log

echo %FILE_NAME%

D:\>date.bat
ex070606.log
 
WOW - Thanks guys. Tried both and they both work, so that's me sorted.

Just curious though, cause even reading the solution I don't understand how it works - like for example;

set FILE_NAME=ex%DATE:~8,2%%DATE:~3,2%%DATE:~0,2%.log

^ how does the above work?

I get the "set FILE_NAME=ex" bit

The rest is dutch to me though.
 
Back
Top Bottom