file comparisons

Irmen de Jong irmen at
Tue Oct 12 19:51:49 CEST 2004

Scott Carlson wrote:
> If I find two Files with the same name, I want to know if the contents
> of the Files are exactly the same (I don't care about the date/time of
> the File).
> If they are different I want to move the new one into the Primary
> Folder.

Something like:-

find files to process using os.listdir() on both directories
and checking for common files, for instance:
commonfiles=sets.Set(os.listdir("tempdir")) & sets.Set(os.listdir("primarydir"))

Loop over the files using os.path.isfile (so you skip the
directories, then for each file read both files into memory using....
f1=open( ....tempfilename....  , "rb").read()
f2=open( ....primaryfilename...  ,"rb").read()

Then compare and move file if unequal:
if f1!=f2:



More information about the Python-list mailing list