Best way to compare the contents of two directories

Dan Dang Griffith google0 at lazytwinacres.net
Sun Sep 12 11:16:38 EDT 2004


robin.siebler at palmsource.com (Robin Siebler) wrote in message news:<95c29a5e.0409111640.6980271f at posting.google.com>...

>I have two directory trees that I want to compare and I'm trying to
>figure out what the best way of doing this would be.  I am using walk
>to get a list of all of the files in each directory.

Once you have the two lists, look into difflib.  E.g.,

import difflib
for i in difflib.ndiff(list1, list2):
    print i

Dan Gass has recently contributed some code that can produce 
a side-by-side difference in HTML format.  I believe it is in the 2.4
release, but you can also get it from 
"""https://sourceforge.net/tracker/?func=detail&atid=305470&aid=914575&group_id=5470"""

import difflib
tbl = difflib.HtmlDiff().make_file(list1, list2)
f = open("diffs.html", "w")
f.write(tbl)
f.close()

    --dang



More information about the Python-list mailing list