for files in glob.glob('%s.*' %name):
import arcgisscripting, os, glob, zipfile from os import path as p # Create the Geoprocessor object gp = arcgisscripting.create() # arcpy.overwriteOutput = True gp.overwriteoutput=1 def ZipShapes(path, out_path): gp.workspace = path shapes = gp.ListFeatureClasses("*") # iterate through list of shapefile for shape in iter(shapes.next, 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) os.chdir(path) for files in glob.glob('%s*' %name): zip.write(p.join(path,files), files) print 'All files written to %s' %zip_path zip.close() if __name__ == '__main__': path = r'T:\\cotiss\CobleJ\shape2zip\address' outpath = r'T:\\cotiss\CobleJ\shape2zip\Shape_outputs' ZipShapes(path, outpath)
import sys, os, string, arcgisscripting, fnmatch from os import path as p import zipfile # Create the Geoprocessor object gp = arcgisscripting.create() # arcpy.overwriteOutput = True gp.overwriteoutput=1 def ZipShapes(path, out_path): gp.workspace = path shapes = gp.ListFeatureClasses("*") # iterate through list of shapefiles #for shape in shapes: for shape in iter(shapes.next, 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 path, dirs, files in os.walk(path): for f in files: if fnmatch.fnmatch(f, '%s*' %shape): zip.write(p.join(path,f), f) print 'All files written to %s' %zip_path zip.close() if __name__ == '__main__': path = r'T:\\cotiss\CobleJ\shape2zip\address' outpath = r'T:\\cotiss\CobleJ\shape2zip\Shape_outputs' ZipShapes(path, outpath)
I get the error, "NameError: global name 'zipflie' is not defined".
zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DELFLATED)
import sys, os, string, arcgisscripting, fnmatch from os import path as p import zipfile # Create the Geoprocessor object gp = arcgisscripting.create() # arcpy.overwriteOutput = True gp.overwriteoutput=1 def ZipShapes(path, out_path): gp.workspace = path shapes = gp.ListFeatureClasses("*") # iterate through list of shapefiles #for shape in shapes: for shape in iter(shapes.next, None): name = p.splitext(shape)[0] print name zip_path = p.join(out_path, name + '.zip') zip = zipfile.ZipFile(zip_path, 'w', zipflie.ZIP_DELFLATED) for path, dirs, files in os.walk(path): for f in files: if fnmatch.fnmatch(f, '%s*' %shape): zip.write(p.join(path,f), f) print 'All files written to %s' %zip_path zip.close() if __name__ == '__main__': path = r'T:\\cotiss\\CobleJ\\shape2zip\\address' outpath = r'T:\\cotiss\\CobleJ\\shape2zip\\Shape_outputs' ZipShapes(path, outpath)
import fnmatch, os for shape in shapes: name = p.splitext(shape)[0]: zip_path = p.join(out_path, name + '.zip') zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) zip.write(p.join(path,shape), shape) for path, dirs, files in os.walk(path): for f in files: if fnmatch.fnmatch(f, '%s*' %shape): zip.write(p.join(path,f), f) print 'All files written to %s' %zip_path zip.close()
gp = arcgisscripting.create(9.3)
for shape in iter(shapes.next, None):
One thing I noticed, though is that it did not actually compress the files (they were archived in zip files but not compressed).
import arcpy, os from os import path as p import zipfile arcpy.overwriteOutput = True def ZipShapes(path, out_path): arcpy.env.workspace = path shapes = arcpy.ListFeatureClasses() # iterate through list of shapefiles for shape in shapes: name = p.splitext(shape)[0] print name zip_path = p.join(out_path, name + '.zip') zip = zipfile.ZipFile(zip_path, 'w') zip.write(p.join(path,shape), shape) for f in arcpy.ListFiles('%s*' %name): if not f.endswith('.shp'): zip.write(p.join(path,f), f) print 'All files written to %s' %zip_path zip.close() if __name__ == '__main__': path = r'C:\Shape_test\Census_CedarCo' outpath = r'C:\Shape_outputs' ZipShapes(path, outpath)
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.