iaav
iaav

Reputation: 466

Windows script to compare folders recursively

I need windows batch script to compare two folders(folder A and folder B) recursively and show only files that are missing in folder A.

I tried this but it's not recursive:

@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

Upvotes: 1

Views: 2177

Answers (2)

marc99
marc99

Reputation: 21

You should use diff.exe : https://code.google.com/p/unix-cmd-win32/downloads/detail?name=diff.exe&can=2&q=

Then, compare the trees :

@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

Upvotes: 0

Jag
Jag

Reputation: 291

Quick way to check would be to try the following

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

Compare both text files to see the difference in files

Upvotes: 4

Related Questions