import os.path, md5 copied = [] def copy (ignore, dir, files): for file in files: if not md5.new (file).digest () in copied: print "Copying %s" % file os.path.walk ('/usr/share/doc', copy, 0)