
文件備份文件對比的批處理是否能再快一點以下代碼,是我找別人幫寫的!備份文件、文件夾。復(fù)制前要作文件對比!只復(fù)制更新、新增的文件、文件夾。復(fù)制完會生成txt日志。但是文件多的話 速度比較慢。例如幾千個小文件,200MB不到。需要好幾分鐘時間!不知道有無其他代碼、方法可以快一點。
nclick="copycode($('code0'));">復(fù)制代碼
- @echo off&setlocal enabledelayedexpansion
- @rem 生成log文件名
- set output=%date:~,4%-%date:~5,2%-%date:~8,2%_%time%.txt
- set output=%output::=-%
- set output=%output: =%
- @rem 調(diào)用函數(shù)完成功能,5個參數(shù)分別是源目錄,目標目錄,用戶名,密碼,log文件名
- @rem 因為windows不允許文件名里有冒號,所以這里把:換成-
- call :s 源地址 目標地址 用戶 密碼 %output::=-%
- @echo 文件已備份完成,30秒后自動關(guān)閉窗口
- @ping -n 30 127.0.0.1>nul
- goto :eof
- :s
- @echo %1 %2 %3 %4 %5
- set src_path=%1
- set dst_path=%2
- set username=%3
- set password=%4
- @rem log生成在目標路徑
- set log_file=!dst_path!rizhi%5
- @rem 創(chuàng)建目錄
- @md !dst_path!rizhi
- @rem 復(fù)制前關(guān)掉xx1.exe和xx2.exe進程
- TASKKILL /IM xx1.exe
- TASKKILL /IM xx2.exe
- @rem 自動登錄局域網(wǎng)電腦(不映射盤),先重啟explorer
- net use !dst_path! /user:!username! !password!
- taskkill /f /im explorer.exe
- start explorer.exe
- @rem 生成log文件
- @echo>!log_file!
- @rem 復(fù)制前能進行對比,已有的文件一模一樣無更新的·不復(fù)制。反之替換掉!
- for /f delims= %%f in ('dir /b/s/a-d^ !src_path!') do (
- @rem 遍歷所有子目錄,獲得文件%%f,然后將%%f中的原路徑替換成目標路徑,便于比較文件
- set cur_file=%%f
- call set dst_file=%%cur_file:%src_path%=%dst_path%%%
- set pathb=%%~dpf
- call set dst_path=%%pathb:%src_path%=%dst_path%%%
- @rem 創(chuàng)建子目錄
- if not exist !dst_path! (@md !dst_path!)
- @rem 這里是正式覆蓋,并且寫入log文件
- @echo xcopy /d /y !cur_file! !dst_path!
- set need_proc=0
- for /F %%i in ('xcopy /d /y !cur_file! !dst_path!^|findstr 復(fù)制了 1 個文件') do (
- set need_proc=1
- )
- if !need_proc!==1 (@echo !cur_file!>>!log_file!)
- )
- :eof

