用于递归比较文件夹的Windows脚本

时间:2014-02-12 21:19:50

标签: windows batch-file scripting

我需要Windows批处理脚本以递归方式比较两个文件夹(文件夹A和文件夹B),并仅显示文件夹A中缺少的文件。

我试过了,但这不是递归的:

@echo off
if "%2" == "" GOTO Usage

cd /D %1
if errorlevel 1 goto usage

for %%x in (*.*) do if NOT exist %2\%%x echo missing %2\%%x
cd /D %2
for %%x in (*.*) do if NOT exist %1\%%x echo missing %1\%%x

goto end

:usage
echo Usage %0 dir1 dir2
echo where dir1 and dir2 are full paths
:end

2 个答案:

答案 0 :(得分:4)

快速检查方法是尝试以下

Cd Folder1
dir *.* /s > Folder1.txt
cd Folder2
dir *.* /s > Folder2.txt

比较两个文本文件以查看文件中的差异

答案 1 :(得分:0)

你应该使用diff.exe: https://code.google.com/p/unix-cmd-win32/downloads/detail?name=diff.exe&can=2&q=

然后,比较树木:

@echo off
if "%1" == "" GOTO Usage
if "%2" == "" GOTO Usage
cd /D %1
if errorlevel 1 goto usage
cd /D %2
if errorlevel 1 goto usage

set TEMP1=C:\temp\dir1
set TEMP2=C:\temp\dir2

dir /s %1 > %TEMP1%
dir /s %2 > %TEMP2%
diff.exe %TEMP1% %TEMP2%

del %TEMP1% %TEMP2%

goto end

:usage
echo Usage %0 dir1 dir2
echo where dir1 and dir2 are full paths
:end
相关问题