本帖最后由 yhcfsr 于 2018-4-20 11:25 编辑
须知:代码第一行是总共备份的次数。在你第一次运行前:如果目标目录没有备份,设置为0;反之有N个备份就设置为N,新的备份命名为diskN+1
这是首次运行的设置,以后无需设置。- @set total_times=0
- @echo off
- set "SrcDir=d:\test\BBC"
- set "desDir=d:\test1"
- set/p "times=input copy times:"
- for /f "delims=" %%a in ("%SrcDir%") do set "name=%%~nxa"
- for /l %%a in (1,1 %times%) do (
- set/a total_times+=1&setlocal enabledelayedexpansion
- if !total_times! lss 10 ( xcopy "%SrcDir%" "%desDir%\%name%0!total_times!" /I /E /Y ) else (
- xcopy "%SrcDir%" "%desDir%\%name%!total_times!" /I /E /Y)
- endlocal
- )
- rem 记录总共运行次数到BAT文件
- (for /f "delims=" %%a in ('type "%0"') do if not defined first (
- echo;@set total_times=%total_times%&set first=1) else (echo;%%a))>"tp"
- move /y "tp" "%0">nul
- pause&exit
复制代码
|