AnsweredAssumed Answered

Help with Exit Code 0 issue

Question asked by lindsay.raabe_FPCWA on Mar 6, 2019
Latest reply on Mar 7, 2019 by lindsay.raabe_FPCWA

I have a basic python code that is intended to take the contents of a File GDB and ZIP them (not that actual .gdb itself though). When I test the code it says it's all good. When I run the code however, it goes straight to "Exit Code 0" and nothing happens. No new ZIP file, nothing. Any ideas where I'm going wrong?

 

import os
import shutil
import zipfile

# Creates a zip file containing the input shapefile
#   inFileGDB: Full path to FileGDB folder to be zipped
#   Delete: Set to True to delete fileGDB files after zip

# Creates a zip file containing the contents of a filegeodatabase
def Zipfgdb(inFileGDB = r'\\my\data\pathway\MyData.gdb', Delete = 'False'):
    print inFileGDB + " : Delete original files = " + Delete
    #Directory of file geodatabase
    inLocation = os.path.dirname (inFileGDB)
    print "inLocation: " + inLocation
    #Base name of shapefile
    inName = os.path.basename (os.path.splitext(inFileGDB)[0])
    print "inName: " + inName
    #Create the zipfile name
    zipfl = os.path.join (inLocation, inName + ".zip")
    print "New ZIP file: " + zipfl
    #Create zipfile object
    ZIP = zipfile.ZipFile (zipfl, "w")
    print "ZIP file created"
    #Iterate files in shapefile directory
    for fl in os.listdir (inFileGDB):
        #Get full path of file
        inFile = os.path.join (inFileGDB, fl)
        #Add file to zipfile. exclude any lock files
        if os.path.splitext(fl)[1][1:] <> 'lock':
            ZIP.write(inFile,fl)
        print "files added to ZIP file"
    #Delete filegeodatabase if indicated
    if Delete == True:
        shutil.rmtree(inFileGDB)
        print "Original file deleted"
    #Close zipfile object
    ZIP.close()
    #Return zipfile full path
    return zipfl

Outcomes