用批处理实现文件备份器V2.3

2019-09-19 07:03:36于海丽

echo         if ^^!file_time^^! lss %%%%~ti set file_time=%%%%~ti^&set file_route=%%%%~dpnxi
echo         if not "%%%%~ti"=="" ^(echo     %%%%~dpnxi    %%%%~ti^>^>"%destination%%name_log%_log.log"
echo         ^) else ^(echo.^&echo                                                %%%%i^)^>^>"%destination%%name_log%_log.log"
echo     ^)
echo     if "%%%%i"=="复制了 1 个文件" goto end
echo ^)

echo ^(
echo echo.
echo echo     最后更新的文件是:%%file_route%% ,更新操作发生在 %%file_time%% 。
echo ^)^>^>"%destination%%name_log%_log.log"
echo :end
echo attrib /s /d +s +r "%destination%*.*"^>nul 2^>nul
echo start "" "%destination%%name_log%_log.log"
echo goto :eof
echo.
)>>"%batch_directory%%name%_backup.bat"
call :build_head
goto build_revert

:file_backup
(
echo xcopy /c /d /h /i /g /q /x /y "%source%" "%destination%"^|findstr /b /e /c:"复制了 0 个文件"^>nul^&^&goto :eof
echo attrib -s -h -r "%destination%*.*"^>nul 2^>nul
echo echo.^>^>"%destination%%name_log%_log.log"
echo for /f "skip=1 tokens=1,2" %%%%i in ^('dir /a-d /tw "%source%"^^^|find "-"'^) do ^(
echo     echo ^^^<%%date:~0,10%% %%time:~0,8%% 备份记录^^^> 文件最后一次更新时间:%%%%i %%%%j^>^>"%destination%%name_log%_log.log"
echo ^)
echo attrib +s +r "%destination%*.*"^>nul 2^>nul
echo start "" "%destination%%name_log%_log.log"
)>>"%batch_directory%%name%_backup.bat"

rem  ========创建文件恢复脚本程序========
:build_revert
:: 恢复备份后文件(夹)的完整路径
for %%i in ("%source%") do set SourceFileName=%%~nxi
:: 判断%source%是文件还是文件夹
if "%folder%"=="yes" (set SourceFiles=%destination%) else (set SourceFiles=%destination%%SourceFileName%)
(
echo @echo off
echo mode con lines=25
echo color 1f
相关文章 大家在看