落絮飞雁的个人网站

顺流而下,把梦做完

桌面文件备份工具

一个批处理,可以方便的备份桌面上的文件.

代码:

@echo off
mode con cols=78 lines=10&color b0
setlocal enabledelayedexpansion
Title 载入中...


::备份文件次数,超过此次数,依次向前替换上一次备份
set strBakCount=10
::目的确路径
set strBakPath=BakFile
::备份路径
set strFo=%userprofile%桌面
::备份类型
set strOP=txt doc xls pdf lnk
::执行命令
set strRunName=桌面文档备份


::备份文件夹初始化
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!s0DatSet.dat echo SaveCount=0 >!strBakPath!!strBakPath!s0DatSet.dat
for /f "tokens=1-2 delims==" %%i in ('type !strBakPath!!strBakPath!s0DatSet.dat') do (
	if /i "%%i"=="SaveCount" set strSaveCount=%%j
	if /i "%%i"=="DateTime" set strDateTime=%%j)
set /a strSaveCount+=0
Title [!strRunName!] - Max:!strBakCount! - Done:!strSaveCount!  - Last Time:!strDateTime!

echo  [备份类型] : %strOP%
echo  [源 路 径] : %strFo%
echo  [目标路径] : %strBakPath%
echo ______________________________________________________________________________
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*.*" !strBakPath!!strBakPath!s!strTmp! >nul 2>nul)
	for %%i in (!strOP!) do copy /y "!strFo!*.%%i" !strBakPath!!strBakPath!s!strBakCount! >nul 2>nul
)else (
	::备份文个夹未满
	set /a strSaveCount+=1

	for %%i in (!strOP!) do copy /y "!strFo!*.%%i" !strBakPath!!strBakPath!s!strSaveCount! >nul 2>nul)
::后续操作
del /q !strBakPath!!strBakPath!s0!strFo! >nul 2>nul
echo SaveCount=!strSaveCount! >!strBakPath!!strBakPath!s0DatSet.dat
echo DateTime=%date:~0,10%,%time:~0,5% >>!strBakPath!!strBakPath!s0DatSet.dat
echo.&echo                             备份完成.&pause>nul



cls&echo.
set /p OP=              是否打开最后一次备份所在文件夹 [y/n]? :
if /i "!OP!"=="y" start !strBakPath!!strBakPath!s!strSaveCount!




原文标题:桌面文件备份工具|落絮飞雁的个人网站
原文链接:https://www.luoxufeiyan.com/2008/08/24/backup-files-on-desktop/
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。