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

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

:build_backup
call :list
title 文件备份器-正在生成备份程序...
if not exist "%ProgramFiles%备份任务程序" md "%ProgramFiles%备份任务程序"
set batch_directory=%ProgramFiles%备份任务程序
attrib /s /d -r -h -s "%batch_directory%*.*">nul 2>nul

:: 因为把所有的批处理内容只用一句 >"%batch_directory%%name%_backup.bat" 来接收,
:: 所以其中的括号都要用 ^ 来转义

(
echo @echo off
echo mode con cols=35 lines=10
echo color 1f
echo title 文件备份器-%name%_backup
echo.
echo rem                        功能说明
echo.
echo rem        本程序由"文件备份器V2.3"生成  Code by JM  2006-10-19 QQ:13132002
echo.
echo rem                 build on %date% %time:~0,-3% by %username%
echo.
echo rem    原理:比较原始文件和备份文件修改日期的早晚,如果原始文件修改时间晚于备份文件,
echo rem          则复制原始文件覆盖备份文件;如果时间没差别,则不作任何处理。
echo.
echo if not exist "%source%" ^(
echo title 文件丢失
echo color 0c
echo echo.
echo echo ___________________________________
echo echo.
echo echo 文件"%source%"
echo echo.
echo ecoh 不存在,可能已被改名、移动或者删除
echo echo.
echo echo ___________________________________
echo ping 127.1 -n 5 ^>nul
echo exit^)
echo if not exist "%destination%" md "%destination%"
)>"%batch_directory%%name%_backup.bat"

set xcopy_parameter=
if "%folder%"=="yes" (set xcopy_parameter=/e /s) else (goto file_backup)

(
echo attrib /s /d -s -h -r "%destination%*.*"^>nul 2^>nul
echo set times=
echo setlocal enabledelayedexpansion
echo for /f "delims=" %%%%i in ^('xcopy /c /d /h /i /g /r %xcopy_parameter% /x /y "%source%" "%destination%"'^) do ^(
echo     if "%%%%i"=="复制了 0 个文件" ^(exit^) else ^(
echo         if not defined times call :head
相关文章 大家在看