Scenario:
Batch File to Append Date
to file name
Solution:
@echo offREM Create a log file with the current date and time in the filename
REM the ~4 in the Date skips the first four characters of the echoed date stamp and writes the remainder and so on
set LOG_FILE_NAME=Example_File_Name.%date:~4,2%%date:~7,2%%date:~10,4%.%time:~0,2%%time:~3,2%%time:~6,2%.txt
Echo This is much easier in UNIX > c: emp\%LOG_FILE_NAME%
:exit
OR
@echo off
for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set y=%%k
for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set d=%%k%%i%%j
for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set t=%%i%%j
set t=%t%_
if "%t:~3,1%"=="_" set t=0%t%
set t=%t:~0,4%
set "theFilename=%d%%t%"
echo %theFilename%
Comments
Post a Comment