标题: 文件备份器
[打印本页]
作者: bluewaterx
时间: 2009-10-22 18:14
标题: 文件备份器
默认备份次数:10次,默认备份类型:*.txt,默认备份路径:当前路径下BakFile
超过10次,依次向前滚动,替换备份时间最早的.
@echo off
mode con cols=78 lines=3&color b0
setlocal enabledelayedexpansion
Title 载入中...
::备份文件次数,超过此次数,依次向前替换上一次备份 [自定义]
set strBakCount=10
::备份路径
set strBakPath=BakFile
::备份类型
set strFo=*.txt
::备份文件夹初始化
md !strBakPath!\ >nul 2>nul
md ...\ >nul 2>nul
for /l %%i in (0,1,!strBakCount!) do (
md !strBakPath!\!strBakPath!s%%i >nul 2>nul
attrib +s +a +r !strBakPath!\!strBakPath!s%%i)
::初始化与读取操作数SaveCount
if not exist !strBakPath!\!strBakPath!s0\DatSet.dat echo SaveCount=0 >!strBakPath!\!strBakPath!s0\DatSet.dat
for /f "tokens=1-2 delims==" %%i in ('type !strBakPath!\!strBakPath!s0\DatSet.dat') do (
if /i "%%i"=="SaveCount" set strSaveCount=%%j
if /i "%%i"=="DateTime" set strDateTime=%%j)
set /a strSaveCount+=0
Title !strBakPath! - 文档上限:!strBakCount! - 已存在!strSaveCount!次备份 - 最后备份时间:!strDateTime!
echo.&echo 按任意键开始备份...&pause>nul
::备份操作判断
if !strSaveCount! geq !strBakCount! (
::备份文件夹已满
for /l %%i in (1,1,!strBakCount!) do (
set /a strTmp=%%i - 1
move /y !strBakPath!\!strBakPath!s%%i\!strFo! !strBakPath!\!strBakPath!s!strTmp!\)
copy /y !strFo! !strBakPath!\!strBakPath!s!strBakCount!\ >nul 2>nul
)else (
::备份文个夹未满
set /a strSaveCount+=1
copy /y !strFo! !strBakPath!\!strBakPath!s!strSaveCount!\ >nul 2>nul)
::后续操作
del /q !strBakPath!\!strBakPath!s0\!strFo! >nul 2>nul
echo SaveCount=!strSaveCount! >!strBakPath!\!strBakPath!s0\DatSet.dat
echo DateTime=%date:~0,10%,%time:~0,5% >>!strBakPath!\!strBakPath!s0\DatSet.dat
cls&echo.&echo 备份完成.&pause>nul
[
Last edited by bluewaterx on 2009-11-4 at 21:37 ]
作者: pkto
时间: 2009-10-22 20:55
呀,好实用的一段批处理,感谢呀!偶也提供一个吧,不过太简陋了:
Start ""/w "C:\Program Files\Microsoft Office\OFFICE11\WINWORD.exe" %1
xcopy /m/d/y/s "d:\资料\*.*" "e:\备份资料\"
是用来每次编辑完“d:\资料”里的稿件后,在关闭word时,就会自动备份一下的
作者: RuiIsRui
时间: 2009-10-23 21:58
偶都看不懂,看来要好好学习了~
作者: slw218856
时间: 2009-11-5 01:04
%1有何用意?谢谢
作者: bluewaterx
时间: 2009-11-6 08:40
Quote: |
Originally posted by slw218856 at 2009-11-5 01:04 AM:
%1有何用意?谢谢 |
|
...接收参数1
eg:
call :subA "hello" 123
pause&exit
:subA
echo %1 %2
goto :eof
作者: xiaodoudou
时间: 2009-11-16 02:09
如果我要修改路径比如修改为e:\该如何修改``我只能修改到在E:\``但是只能备份一个