AnsweredAssumed Answered

Unable to Zip due to GDB lock

Question asked by Scott.Fierro on Sep 1, 2016
Latest reply on Sep 1, 2016 by Scott.Fierro

I am trying to automate a process to take a directory given by the user which contains a file geodatabase and zip it with only the relative path being retained. Intended output is a ZIP that contains just the final folder with the FGDB inside of it.

 

The workflow is to take a feature class from SQL SDE and use "Feature Class to Feature Class" tool to load desired data into the FGDB. Next perform the zip below. When running this it returns this message:

 

Traceback (most recent call last):

File "C:\arcgisserver\ETL_Scripts\Scripts\Zipdir.py", line 19, in <module>

zipdir(directory, zip)

File "C:\arcgisserver\ETL_Scripts\Scripts\Zipdir.py", line 13, in zipdir

ziph.write(os.path.relpath(os.path.join(root, file), os.path.join(path, '..')))

File "C:\Python27\ArcGIS10.2\Lib\zipfile.py", line 1033, in write

st = os.stat(filename)

WindowsError: [Error 3] The system cannot find the path specified: u'Output\\Output.gdb\\a00000001.freelist'

 

This folder remains unable to be zipped until I close out of ArcCatalog which removes the .lock file from within the .gdb. This isn't an acceptable workflow to have to do in order to perform the zip as this is 1 step of about 15+ that needs to be able to be published into a service for automation. The code below is what I am using that creates this issue. Thanks for any assistance.

import os, arcpy, zipfile

directory = arcpy.GetParameterAsText(0)
outputFile = arcpy.GetParameterAsText(1)


def zipdir(path, ziph):
    #ziph is zipfile handle
    for root, dirs, files in os.walk(path):
        for file in files:
         if not file.endswith('.lock'):
             ziph.write(os.path.relpath(os.path.join(root, file), os.path.join(path, '..')))
          


if __name__ == '__main__':
     zip = zipfile.ZipFile(outputFile, 'w', zipfile.ZIP_DEFLATED)
     zipdir(directory, zip)
     zip.close()

Outcomes