AnsweredAssumed Answered

Adding extra files to a zip?

Question asked by jemmaable on Jan 19, 2016
Latest reply on Jan 19, 2016 by lsturtevant

So I got this fantastic script from: Script for Making Individual Zip file for Each Shapefile? but I required some extra files to be added to each of the individual zips, e.g. 2 pdfs: one with metadata and another for terms and conditions. 


import arcgisscripting, os, glob, zipfile, shutil

from os import path as p


# Create the Geoprocessor object

gp = arcgisscripting.create()


# arcpy.overwriteOutput = True



def ZipShapes(path, out_path):

    gp.workspace = path

    shapes = gp.ListFeatureClasses("*")


    # iterate through list of shapefile

    for shape in iter(, None):

        name = p.splitext(shape)[0]

        print name

        zip_path = p.join(out_path, name + '.zip')

        zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)


        for files in glob.glob('%s.*' %name):

            zip.write(p.join(path,files), files)

        print 'All files written to %s' %zip_path

        # copy pdf files to zip folder

        for f in pdfList:

            shutil.copyfile(os.path.join(os.path.dirname(path),f), os.path.join(path,f))



if __name__ == '__main__':


    path = r'S:\Species\MARINEFISH'

    outpath = r'S:\Species\MARINEFISH\ZIPS'

    pdfList =["Terms & Conditions of Use.pdf", "METADATA.pdf"]


    ZipShapes(path, outpath)


I keep getting the error:

Traceback (most recent call last):

  File "S:\scripts\Python\Zipping_Shapefiles", line 34, in <module>

    ZipShapes(path, outpath)

  File "S:\scripts\Python\Zipping_Shapefiles", line 25, in ZipShapes

    shutil.copyfile(os.path.join(os.path.dirname(path),f), os.path.join(path,f))

  File "C:\Python27\ArcGIS10.3\lib\", line 82, in copyfile

    with open(src, 'rb') as fsrc:

IOError: [Errno 2] No such file or directory: 'S:\\Species\\METADATA.pdf'


Any help would be greatly appreciated!