file comparisons
Irmen de Jong
irmen at -nospam-remove-this-xs4all.nl
Tue Oct 12 13:51:49 EDT 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:
shutil.move("filename1","filename2")
(Untested)
--Irmen
More information about the Python-list
mailing list