file comparisons

Rick Holbert holbertr at dma.org
Tue Oct 12 19:43:49 CEST 2004


Scott,

The following example is based on code from The Standard Python Library:

http://effbot.org/zone/librarybook-index.htm

import filecmp

if filecmp.cmp("folder1/file.ext", "folder2/another.ext"):
    print "file contents are the same"
else:
    print "file contents differ"


Scott Carlson wrote:

> Still new to Python, but liking it.
> 
> Using Windows.
> 
> Synopsis:
> 
> I create some files in a Temporary Folder while doing some work.
> 
> Then, I want to look in a (different)Primary Folder to see if
> similarly named Files exist.
> 
> 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.
> 
> 
> I'm thinking there's a nice concise way to do this.
> 
> Thanks,
> Scott Carlson




More information about the Python-list mailing list