check if files are the same on Windows

Beliavsky beliavsky at aol.com
Mon Mar 19 12:09:47 EDT 2007


A crude way to check if two files are the same on Windows is to look
at the output of the "fc" function of cmd.exe, for example

def files_same(f1,f2):
    cmnd    = "fc " + f1 + " " + f2
    return ("no differences" in popen(cmnd).read())

This is needlessly slow, because one can stop comparing two files
after the first difference is detected. How should one check that
files are the same in Python? The files are plain text.




More information about the Python-list mailing list