Shutil module issue

I have a Python script below, which has worked properly in the past, but lately is creating an additional zip file inside the main zip file. Using Python 2.7.13; have also tried running with Python 3.7.10.

import shutil

shutil.make_archive('C:\\temp\\FGDB\\PD_DATA_PROD','zip','C:\\temp\\FGDB')

ZIPFILE = 'C:\\temp\\FGDB\\PD_DATA_PROD.zip'

shutil.copy(ZIPFILE, 'Z:\\Group\\GISServices\\Addressing\\Data')

print("Completed new zip file")

I can see that it is making a copy of the zip file within upon Line 3 (prior to copying to another directory location).

Have you checked the contents of C:\\temp\\FGDB? I’m just wondering if
it already contains the unexpected zip file, maybe accidentally placed
there? Doing a listing of that folder just before the make_archive()
call may be informative.

Cheers,
Cameron Simpson cs@cskk.id.au

Hi Barry,

You say your script worked in the past, but “lately is creating an additional zip file inside the main zip file.”

We cannot guess what the additional zip file is. But you can tell us:

  • what is the name of the unexpected zip file?

  • what is inside it?

  • have you double and triple checked that it actually is unexpected, and not just a zip file that exists in the directory being archived?

Your code:

shutil.make_archive('C:\\temp\\FGDB\\PD_DATA_PROD','zip','C:\\temp\\FGDB')
ZIPFILE = 'C:\\temp\\FGDB\\PD_DATA_PROD.zip'
shutil.copy(ZIPFILE, 'Z:\\Group\\GISServices\\Addressing\\Data')

You are creating your zip file inside the same directory that is being
archived. That is dangerous:

Depending on how the make_archive function is written, it could create the zip file inside the archive directory and then archive itself.

If it did that, I would consider it a bug in make_archive. Especially if it previously worked correctly, and then after an upgrade started duplicating the zip inside itself.

By the way, Windows can use forward slashes as the path separator, so you don’t need all those doubled-up backslashes. Here is the same code written more nicely:

shutil.make_archive('C:/temp/FGDB/PD_DATA_PROD','zip','C:/temp/FGDB')
ZIPFILE = 'C:/temp/FGDB/PD_DATA_PROD.zip'
shutil.copy(ZIPFILE, 'Z:/Group/GISServices/Addressing/Data')

I suggest you move the zip file to a different location, say ‘C:/temp’, so that there is no chance that the archiver will duplicate its own archive inside the archive.

P.S. I see that make_archive has a verbose parameter which would be handy here, so you could see what files were being archived, but it’s been deprecated and is now ignored. Does anyone know why?