@echo off
REM ————————————————————————————
REM Beginning of Batch file copylogs.bat
REM ————————————————————————————
for /f “tokens=1-5 delims=/ ” %%d in (“%date%”) do rename “import.log” %%e-%%f-%%g-log.txt
REM ————————————————————————————
REM Description Follows
REM ————————————————————————————
REM for /f – The for command and the /f switch.
REM Loop command: against a set of files – conditionally perform a command against each item.
REM “tokens=1-5 delims=/ “ – How many tokens the input data will be
REM broken into;
REM 1-5 is five different tokens. Finally, delims is short for delimiters and is what is used
REM to break up the date, in this example the ‘/’ and a space.
REM %%d – The beginning character used for the token.
REM There are 5 tokens in the example:
REM d,e,f,g, h
REM When %date% is used in a batch file it displays the date the following format:
REM Sun 09/02/2007 this command breaks this date into the tokens:
REM “Sun” (%%d), “09” (%%e), “02” (%%f), and “2007” (%%g).
REM in (“%date%”) – The data being used, in this case the REM %date% is the current date of the computer.
REM do – What the for command will do.
REM copy “import.log” %%e-%%f-%%g-log.txt –
REM copy the file “import.log” to the tokens e,f, and g with a .txt file extension.
REM This example also has a hyphen in between each token to separate the
REM month, day, and year in the file name.
REM The final result would be that import.log is copied to:
REM 12-28-2007-log.txt.