Windows 备份文件夹脚本

目的:将C:\pac下的内容,备份到M:\cpac下的时间戳文件夹下。

脚本内容:

@echo off
set YEAR=%date:~0,4%
set MONTH=%date:~5,2%
set DAY=%date:~8,2%
set HOUR=%time:~0,2%
set MINUTE=%time:~3,2%
set SECOND=%time:~6,2%
set TMP_HOUR=%time:~1,1%
set NINE=9
set ZERO=0
if %HOUR% LEQ %NINE% (
    set HOUR=%ZERO%%TMP_HOUR%
)

set CURRENT_DATE_TIME_STAMP=%YEAR%%MONTH%%DAY%_%HOUR%%MINUTE%%SECOND%
echo %CURRENT_DATE_TIME_STAMP%
set BAKDIR_ROOT=M:\cpac
set BAKDIR=%BAKDIR_ROOT%\%CURRENT_DATE_TIME_STAMP%
set WORKDIR=C:\pac

if exist %WORKDIR% (    
    echo %WORKDIR% exist!       
) else (  
    echo create dir %WORKDIR%  
    md %WORKDIR%  
)
if exist %BAKDIR% (  
    echo %BAKDIR% exist!     
) else (  
    echo create dir %BAKDIR%  
    md %BAKDIR%  
)  

xcopy %WORKDIR% %BAKDIR% /e/I/d/h/r/y
exit