Back to the main page

Compare files in two directories

Sometimes I have two versions of a directory stored on my computer. When cleaning up, it is handy to be able to see which files are in common and which files differ. To do that, I wrote a small Python script that compares two directories. The script also shows duplicate files in each of the directories. MD5 checksums are used to determine if files are equal – no file name comparison is used. Also, the script goes recursively into subdirectories.

Download script (

The usage is simple:

Usage: [-d] dir1 dir2
Compares files in two directories, based on their MD5 checksum.
-d: Debug. Prints the MD5 checksum of every file to stderr.

Sample usage and output:

% python dir1 dir2
Duplicate files

dir1/file 2.pdf

Common files



Files only in dir1


Files only in dir2


2 Responses to “Compare files in two directories”

  1. Eurodipity Says:

    Thanks for the script…

  2. jang Says:

    How can i modify this script to compare files in 2 directories?
    my first directory (BTS) is 536MB and contains 2355 files. Second directory (SCM) is 2.44GB and contains 1,757 files. blog is powered by WordPress
Entries (RSS) and Comments (RSS).