1

I'm migrating a BASH script that zips a directory as such:

zip -q -r -X ../$myFolder.zip *.*

to Python, which uses a function such as:

def zipDirectory (srcDir):
    (myPath,myLeaf) = os.path.split(srcDir)
    myFiles = os.listdir(srcDir)
    if len(myFiles) >= 1:
        myArchiveDir = os.path.join(myPath, myLeaf + ".zip")
        myArchive = zipfile.ZipFile(myArchiveDir, 'w')
        for myFile in myFiles:
            myArchive.write(os.path.join(srcDir,myFile), myFile)
        myArchive.close()
        return myArchiveDir

It appears as though the zip archives created by my Python script are a consistently larger than the zip archives from my Bash script (despite the fact that they have exactly the same files). Could somebody enlighten me as to why this is happening? My guess would be maybe the -X parameter, which "Does not save extra file attributes" doesn't apply in Python. If this is correct, how can I apply it?

Dharman
  • 30,962
  • 25
  • 85
  • 135
JHowzer
  • 3,684
  • 4
  • 30
  • 36
  • 1
    Have you compared the output from `unzip -lv` on both the archives? – Etan Reisner Jan 16 '15 at 18:17
  • Hi Etan Reisner, I just did. it appears that the Method, Size, and Ratio columns are different in the output. Method for my bash results has Defl:N vs Stored in Python. Also, sizes are larger in the Bash results and all the ratios are at 0% in the Python output. I'm assuming this means I should use the DEFLATED parameter in Python's zipfile (as opposed to the default). Correct? If so, thank you for pointing me in the right direction in a useful way! – JHowzer Jan 16 '15 at 18:21

0 Answers0