creating log files with date and time in their names.

Often want to create a log file from a cmd batch script which is unique for each day

for /F "tokens=1-6 delims=/ "  %%A in ('date /t') do ( set dt=%%D_%%C_%%B_)
for /F "tokens=1-6 delims=: "  %%A in ('time /t') do ( set tt=%%A_%%B_%%C)

set logfile="x:\LogFiles\%dt%_%tt%_nanotera.log"
echo %logfile%

@date /t  >> %logfile%
@time /t  >> %logfile%
@echo %0  >> %logfile%
@echo Backup Data folder. >> %logfile%
@echo ------------------- >> %logfile%

About Jeff Turner

Technical director of Nano Tera Network Solutions.
This entry was posted in Powershell, VBS, VBA and other scripting. and tagged . Bookmark the permalink.