Compare two folders

J

Jason K

Is there a product or VB code that compares two folders and provides the
delta? For example the files that are new or changed and the total size
difference. I want to compare two servers and what has changed
 
K

Keme

Jason said:
Is there a product or VB code that compares two folders and provides the
delta? For example the files that are new or changed and the total size
difference. I want to compare two servers and what has changed

Off topic as it is, I'll take my chances...
The power of the command line is much overlooked. (Can probably be done
more elegantly using sophisticated scripting engines, but this will work
consistently on client computers with OS from MS-DOS 6.0 upwards.)

What you need is a "delta.bat" text file (use a pure text editor, like
notepad) containing the following lines:

---------------------
dir %1 /s /a-d /on >1.tmp
dir %2 /s /a-d /on >2.tmp
fc /L 1.tmp 2.tmp >delta.txt
---------------------

you then issue the following command: delta.bat "dir1" "dir2", and get a
diff file named "delta.txt".

For a more robust utility, use the commands below:

---------------------
@echo off
REM Error checking, providing robustness
if "%2"=="" goto error
if "%1"=="" goto error

REM MS command line does not provide check for directory existence.
REM Trick: Testing for availability of null device at directory location
if not exist %1\nul goto error
if not exist %2\nul goto error

REM Given directories validated. List files in alphabetical order...
dir %1 /s /a-d /on >1.tmp
dir %2 /s /a-d /on >2.tmp

REM Comparing
fc /L 1.tmp 2.tmp >delta.txt
if errorlevel 2 goto error
if errorlevel 1 goto diff_detected

echo There are no differences

REM remove old results, to avoid confusion
if exist delta.txt del delta.txt
goto done

:diff_detected
edit delta.txt
goto done

:error
cls
echo An error has occurred. Check that the following conditions are met:
echo.
echo - Command line format: %0 directory1 directory2
echo - The directory specs should be valid paths
echo - If the paths contain spaces, they must be quoted, like this:
echo --- %0 "Program files" "\backupdir\program files"
echo - You need write permission to the current directory

echo for storing delta.txt and temporary files.

:done
REM Remove temporary data
del 1.tmp
del 2.tmp

echo Any differences are written to the file "delta.txt"
---------------------
 
Top