码迷,mamicode.com
首页 > 其他好文 > 详细

写了一个批处理,可以实现文件备份,自动对比删除冗余文件。

时间:2014-12-07 20:22:30      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   ar   color   sp   for   on   

替换的原则是按照文件修改时间,替换掉修改时间教早的。

set desdir=D:set filetypes=pdf uvproj bat c h s lib cpp txt rar



del /s /q s:\backtempsrc.t>nul
del /s /q s:\backtempdes.t>nul
del /s /q s:\dellist.t>nul
cls
@echo off&setlocal enabledelayedexpansion


set /p sels="是否扫描数据冗余?(Y/N) sel="
if "%sels%"=="Y" goto section1
goto section2

:section1
echo 删除冗余文件-----------------------------------------
echo -文件扫描
for /f "delims=" %%i in (cd) do set srcdir=%%i
for /f "delims=" %%i in (dir /s /b) do (
set thistemp=%%i
echo !thistemp:%srcdir%=!>>s:\backtempsrc.t
)
for /f "delims=" %%i in (dir /s /b "%desdir%") do (
set thistemp=%%i
echo !thistemp:%desdir%=!>>s:\backtempdes.t
)
echo -文件对比
for /f "delims=" %%i in (s:\backtempdes.t) do (
set flags=1
for /f "delims=" %%j in (s:\backtempsrc.t) do (
if "%%i"=="%%j" set flags=0
)
if !flags!==1 (
echo %desdir%%%i
echo %%i>>s:\dellist.t
)
)
if exist s:\dellist.t (
for /f "delims=" %%i in (s:\dellist.t) do (
rd /s /q "%desdir%%%i">>nul
del /s /q "%desdir%%%i">>nul
)
)
echo 冗余文件删除完毕
echo *****************************************************
echo.
echo.


:section2
echo 开始备份:-------------------------------------------
for %%i in (%filetypes%) do (
xcopy *.%%i "%desdir%\" /S/I/d/h/r/y
)
echo _____________________________________________________
echo.
echo 备份完成 按任意键退出!
pause>nul

del /s /q s:\backtempsrc.t>nul
del /s /q s:\backtempdes.t>nul
del /s /q s:\dellist.t>nul

注意,我的电脑里面有个S盘,是个虚拟内存盘,所以讲临时生成的文件放在那里,如果没有的需要改下批处理里的s:\盘符。

(by:cntsw 转载请注明出处)

写了一个批处理,可以实现文件备份,自动对比删除冗余文件。

标签:des   style   blog   io   ar   color   sp   for   on   

原文地址:http://www.cnblogs.com/cntsw/p/4149763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!