乙個比較「子資料夾差異」的 DOS 批處理指令碼

2021-06-15 20:08:16 字數 1780 閱讀 3002

鑑於自詡為「程式設計師大本營」的 csdn blog 卻對

這個最適合貼**的標籤不支援,致使**變為1行的現象,我已將該文放在我的 wiki 上,有興趣的可以瀏覽:

該指令碼來比較自上次執行該指令碼以來,當前資料夾的子資料夾與上次的差別

@echo off

setlocal

set dircmd=/ad /on /b

if not exist old.txt (

dir > old.txt

goto lblendlocal

)echo. > log.txt

dir > new.txt

echo n | comp old.txt new.txt

echo.

if "%errorlevel%" == "0" (

goto lblendlocal

)echo -------------------------------------- >> log.txt

echo 已刪除的資料夾: >> log.txt

for /f "tokens=*" %%o in (old.txt) do (

call :lblsubprocessdeleted "%%o"

)echo. >> log.txt

echo -------------------------------------- >> log.txt

echo 新增的資料夾: >> log.txt

for /f "tokens=*" %%n in (new.txt) do (

call :lblsubprocessadded "%%n"

)copy /y new.txt old.txt

rem 傳送郵件

if defined cygwin_home (

%cygwin_home%/bin/email --version

if "%errorlevel%" == "0" (

%cygwin_home%/bin/email --subject "資料夾有變化" [email protected] < log.txt

) else (

echo 未安裝 email 工具

)) else (

echo 未安裝 cygwin 仿 unix 環境

):lblendlocal

endlocal

goto :eof

:lblsubprocessdeleted

findstr /x /c:%1 new.txt > nul

rem echo %errorlevel%

if "%errorlevel%" == "0" (

rem echo "%~1 found in new.txt!"

) else (

rem echo %~1 not found in new.txt! it's deleted

echo %1 >> log.txt

)goto :eof

:lblsubprocessadded

findstr /x /c:"%~1" old.txt > nul

rem echo %errorlevel%

if "%errorlevel%" == "0" (

rem echo %~1 found in old.txt!

) else (

rem echo %~1 not found in old.txt! it's added

echo %1 >> log.txt

)goto :eof

乙個拷貝整個資料夾 包括子資料夾 的方法

需要引用命名空間 using system.io 拷貝資料夾 包括子資料夾 到指定資料夾下,源資料夾和目標資料夾均需絕對路徑.格式 copyfolder 源資料夾,目標資料夾 public static void copyfolder string strfrompath,string strtop...

乙個拷貝整個資料夾 包括子資料夾 的方法

需要引用命名空間 using system.io 拷貝資料夾 包括子資料夾 到指定資料夾下,源資料夾和目標資料夾均需絕對路徑.格式 copyfolder 源資料夾,目標資料夾 public static void copyfolder string strfrompath,string strtop...

乙個拷貝整個資料夾 包括子資料夾 的方法

需要引用命名空間 using system.io 拷貝資料夾 包括子資料夾 到指定資料夾下,源資料夾和目標資料夾均需絕對路徑.格式 copyfolder 源資料夾,目標資料夾 public static void copyfolder string strfrompath,string strtop...