Issue
My script is zipping up some files with zipfile, but the archive seems to be missing the CRC values.
Why does this happen?
Here is my code:
import os.path
import zipfile
from glob import glob
from sys import exit
def dozip():
file_list = glob("C:/python27/scripts/*.py")
zf = zipfile.ZipFile("myzip.zip", 'w')
for f in [f.replace("/", os.sep) for f in file_list]:
print f
if os.path.exists(f):
filepath, f = os.path.split(f)
zf.write(os.path.join(filepath, f) if filepath.strip() else f, f,
compress_type=zipfile.ZIP_DEFLATED)
def main():
dozip()
raw_input("Finished zipping the archive. Press enter to quit ")
exit()
if __name__ == "__main__":
main()
Here is a screenshot of winrar
Running win7 x64 & python 2.7.
Solution
It's because zipfile only calculates the CRC when you close the archive, so when you interact with the archive before the script closes the archive, it will be missing the CRCs. So you need to manually close it before calculating the CRC, otherwise the CRC will be null.
Call zf.close()
at the end of dozip
.
Answered By - Texdarkstar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.