Handy batch code

Antony showed me this code snippet couple of days ago. If you want to copy a directory to another location as datetime being filename the traditional batch way, following is the go to script.


@echo off
rem Extract date time to filename-compatible format


for /f "tokens=1-4 delims=/ " %%i, in ('echo %date%') do set filedate=%%l-%%k-%%j
for /f "tokens=1-3 delims=: " %%i, in ('time /t') do set filetime=%%i-%%j-%%k


for /f "tokens=1-4 delims=/ " %%i, in ('echo %date%') do set datevar=%%j-%%k-%%l
for /f "tokens=1-3 delims=: " %%i, in ('time /t') do set timevar=%%i:%%j:%%k


mkdir c:\%filedate%_%filetime%
xcopy c:\PNTDATA c:\%filedate%_%filetime% /E /C /H /R /Y /G /q

Share