zoukankan      html  css  js  c++  java
  • 写了一个批处理,可以实现文件备份,自动对比删除冗余文件。

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

    set desdir=D:
    set filetypes=pdf uvproj bat c h s lib cpp txt rar
    
    
    
    del /s /q s:acktempsrc.t>nul
    del /s /q s:acktempdes.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:acktempsrc.t
    )
    for /f "delims=" %%i in ('dir /s /b "%desdir%"') do (
    set thistemp=%%i
    echo !thistemp:%desdir%=!>>s:acktempdes.t
    )
    echo -文件对比
    for /f "delims=" %%i in (s:acktempdes.t) do (
    set flags=1
    for /f "delims=" %%j in (s:acktempsrc.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:acktempsrc.t>nul
    del /s /q s:acktempdes.t>nul
    del /s /q s:dellist.t>nul

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

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

  • 相关阅读:
    Java反射
    浅谈page,request,session,application四种范围
    使用MySQL连接池
    SQL注入漏洞的演示及解决办法
    JDBC工具类的提取
    JDBC使用过程
    MYSQL常用函数
    MySQL数据操作
    MySQL存储引擎
    Python核心技术与实战——六|异常处理
  • 原文地址:https://www.cnblogs.com/cntsw/p/4149763.html
Copyright © 2011-2022 走看看