bat 生成以当前时间的文件名
如何在bat中产生以当前系统时间为基准的文件夹。
脚本如下。欢迎拍砖。
代码:GenerateFileNameBasedOnDate
ECHO. |date >temp1
FOR /F "eol=T tokens=5 delims=() " %%i in (temp1) do set date_format=%%i
FOR /F "eol=E tokens=5,6,7,8 delims=/- " %%a in (temp1) do (
REM Check whether reguler or not.
SET NORMAL=0
ECHO %%d | FINDSTR /R "[0-9]"
IF %ERRORLEVEL% EQU 0 SET NORMAL=1
IF /I %date_format% EQU mm-dd-yy (
IF !NORMAL!==0 set month=%%a& set day=%%b& set year=%%c& set week=%%d
IF !NORMAL!==1 set month=%%b& set day=%%c& set year=%%d& set week=%%a
)
IF /I %date_format% EQU dd-mm-yy (
IF !NORMAL!==0 set day=%%a& set month=%%b& set year=%%c& set week=%%d
IF !NORMAL!==1 set day=%%b& set month=%%c& set year=%%d& set week=%%a
)
IF /I %date_format% EQU yy-mm-dd (
IF !NORMAL!==0 set year=%%a& set month=%%b& set day=%%c& set week=%%d
IF !NORMAL!==1 set year=%%b& set month=%%c& set day=%%d& set week=%%a
)
)
ECHO. |time >temp2
FOR /F "eol=E tokens=5-8 delims=:. " %%A in (temp2) do (
set hour=%%A
set minute=%%B
set second=%%C
set hundredth=%%D
)
REM SET current_date=%year%%month%%day%
REM SET current_time=%hour%%minute%%second%%hundredth%
SET %1=%year%%month%%day%%hour%%minute%%second%
IF %hour% LEQ 9 SET %1=%year%%month%%day%0%hour%%minute%%second%
IF EXIST temp1 DEL /Q temp1
IF EXIST temp2 DEL /Q temp2
GOTO EOF
posted on 2010-07-08 14:20 Joe.W.Chen 阅读(988) 评论(0) 编辑 收藏 举报