Menu

Home

Dmitry Zaharov

About

DirComp.NET is a simple command-line tool written in VB.NET, which compares two directories, and either lists differences or mirrors one directory onto another. For example, it can be used to backup large file repository by maintaining a mirror copy. It lives well with existing Windows infrastructure, which already provides file shares. And finally, DirComp.NET is based on .NET Framework 2.0, which is available from Windows 2000 and up.

Why it deserves space on SourceForge

A few similar tools exist for directory comparison and synchronization tools, of which author experienced RSync for Windows and FreeFileSync. In my opinion, RSync works best at minimizing network traffic between Unix servers, while FreeFileSync's main strenth is ease of use and intuitiveness of GUI. DirCompNet was built with Windows system administrator in mind, as setup and configuration cannot be easier for those who have a few dozen Windows servers in a gigabit LAN and have no requirement of syncing FTP directories over slow bandwidth links.

Method of comparing files

When identifying differences, DirComp.NET looks at two attributes:

a) time of last modification
b) file size.

Identify differences

This command outputs differences to the stdout:

dircomp diff <pathA> <pathB>

Example:

C:\dircomp diff C:\dirA C:\dirB
Starting diff C:\dirA\ C:\dirB\ at 1/8/2013 5:11:56 PM
images\IMG_0769.JPG - newer in B
Completed in 0.4240424 seconds

Sync changes from A to B

This copies directory A onto directory B. Only changes are copied. In the end, directory B looks like directory A.

dircomp copyAB <dirA> <dirB>

Example:

C:\dircomp copyAB C:\dirA C:\dirB
Starting copyAB U:\1\HTML\ U:\2\HTML\ at 1/8/2013 5:17:25 PM
copying...images.2\image\IMG_0769.JPG - OK
Completed in 0.2130213 seconds

Auditing backup process

Following .BAT file backs up shared directory MyFiles and records audit trail in the log file, named by current date:

:: determine current date for log file naming
FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
    SET Month=%%A
    SET Day=%%B
    SET Year=%%C
)

SET LogFileName=C:\LoggingRoot\BackupOfMyFilesAuditTrail\%Year%%Month%%Day%.txt
C:\DirComp\DirComp.exe copyAB \\MyServer\MyFiles E:\BackupOfMyFiles\ > %LogFileName%

Using Source Code

From developer's perspective, DirComp employs a team of classes to complete work. DirectoryComparer is the main class, which maps 'work to be done' by walking two trees side-by-side. Algorithm streams one directory at a time, from each source path, which enables efficient processing of very large trees. Two 'worker' classes ConsoleNotifier and CopyAtoBNotifier accept notifications from DirectoryComparer, and either display results to console or execute copy. Both inherit from GenericNotifier.

Project Admins: