mafic9

Zipping multiple shapefiles to multiple zip folders

Discussion created by mafic9 on May 25, 2011
Latest reply on Mar 10, 2015 by johnswood
Hello, I am new to scripting and am working with a piece of code that can zip one shapefile to one zip folder, and would like to know if anyone out there can give me some pointers to converting the code to zip multiple shapefiles (within the same folder) into multiple (separate) zip folders. here is the code I have at the moment:

import zipfile, sys, os, glob

testShapeFile = ("C:/Data/Test.shp"
testZipFile = "C:/Data/Test.zip"

def zipShapefile(inShapefile, newZipFN):
    print 'Starting to Zip '+(inShapefile)+' to '+(newZipFN)
   
    if not (os.path.exists(inShapefile)):
        print inShapefile + ' Does Not Exist'
        return False

    if (os.path.exists(newZipFN)):
        print 'Deleting '+newZipFN
        os.remove(newZipFN)

        if (os.path.exists(newZipFN)):
            print 'Unable to Delete'+newZipFN
            return False
       
    zipobj = zipfile.ZipFile(newZipFN,'w')

    for infile in glob.glob( inShapefile.lower().replace(".shp",".*")):
        print infile
        zipobj.write(infile,os.path.basename(infile),zipfile.ZIP_DEFLATED)

    zipobj.close()

    return True

zipShapefile(testShapeFile,testZipFile)
print "done!"


Any help is greatly appreciated.

Thank you

I noticed the indentation is not correct in my post, but is in my script as it does run, I just wanted to point that out. Thank you again in advance

Outcomes