Comparing files in a zip to files on drive

Justin Ezequiel justin.mailinglists at gmail.com
Thu Dec 28 22:15:03 EST 2006


kj7ny wrote:
> compare a file on a hard drive to a file in a python created zip file
> to tell if the file has changed?

>>> fileondisk = r'C:\Documents and Settings\power\Desktop\ES3dc+Template.3f'
>>> zipondisk = r'C:\Documents and Settings\power\Desktop\temps.zip'
>>> import zipfile
>>> z = zipfile.ZipFile(zipondisk)
>>> z.namelist()
['ES1+Template.3f', 'ES3sc+Template.3f', 'ES3dc+Template.3f']
>>> info = z.getinfo('ES3dc+Template.3f')
>>> info.CRC
1620938006
>>> import binascii
>>> checksum = 0
>>> fp = open(fileondisk, 'rb')
>>> while 1:
... 	data = fp.read(32*1024)
... 	if not data: break
... 	checksum = binascii.crc32(data, checksum)
... 	
>>> checksum
1620938006
>>>




More information about the Python-list mailing list