Monday, March 14, 2011

BATCH FILE Time Date delimit tokens for random files and random numbers


@cls
@echo off
@cls
@echo. Deleting old logs in "%temp%"
::if errorlevel==1 @del /s /q "%temp%\*.log"
if not exist "%temp%\*.log" @del /s /q "%temp%\*.log"
@Title Batch Created by :[sonukaushik (AMK)][V1.0][File:DateTime_delimiter.bat]
@echo.
@echo. Token this date^/time ^<%date% %time%^>
@echo.

FOR /F "tokens=1-8 delims=/.: " %%a IN ('echo %date% %time%') DO (
set dy=%%a
set mn=%%b
set dd=%%c
set yy=%%d
set hh=%%e
set mm=%%f
set ss=%%g
set ms=%%h
)
@echo.
@echo This is token format for date^/time :%dy% %mn% %dd% %yy% %hh% %mm% %ss% %ms%
@echo.

@echo day is dy [%dy%]
@echo month is mn [%mn%]
@echo date is dd [%dd%]
@echo year is yy [%yy%]
@echo hour is hh [%hh%]
@echo minute is mm [%mm%]
@echo second is ss [%ss%]
@echo millisecond is ms [%ms%]

@echo.
@echo.Create Random time file as MY_LOG_FILE_%dy%_%mn%-%dd%-%yy%-%hh%-%mm%-%ss%-%ms%.log
@echo.

@echo.
@echo. > "%temp%\MY_LOG_FILE_%dy%_%mn%-%dd%-%yy%-%hh%-%mm%-%ss%-%ms%.log"
@echo.
@echo.

@echo.
@dir /b /t:w %temp%\*%ms%.log
@echo.

@echo.
@dir /x /o:d %temp%\*%ms%.log
@echo.

@echo. - END OF SCRIPT -


FOR %%a IN (%dy%) DO set dy=%%a && echo %dy%
FOR %%a IN (%mn%) DO set dd=%%b && echo %dd%
FOR %%a IN (%dd%) DO set mn=%%c && echo %mn%
FOR %%a IN (%yy%) DO set yy=%%d && echo %yy%
FOR %%a IN (%hh%) DO set hh=%%e && echo %hh%
FOR %%a IN (%mm%) DO set mm=%%f && echo %mm%
FOR %%a IN (%ss%) DO set ss=%%g && echo %ss%
FOR %%a IN (%ms%) DO set ms=%%h && echo %ms%

pause

dateTime.gif

No comments: