I made the attached script here into a tool (ArcMap 10.4). When running it the append2Zip() function starting on line 50 appends the txt file to a zipfile as it should, but doesn't overwrite the old one. I run this tool weekly. The other two blocks run as they should (i.e. output overwrites old files). The first block is lines 9-32. The second is 34-48. And the one I'm concerned with is lines 50-60.
Can anyone catch why the append2Zip function isn't overwriting?
import arcpy
import os
import zipfile
from arcpy import env
from os import path as P
arcpy.env.overwriteOutput = True
ws = r'\\gisfile\GISstaff\Jared\Python Scripts\Data'
mxd = arcpy.mapping.MapDocument(r'\\gisfile\GISstaff\Jared\Python Scripts\Data\Data_Request.mxd')
addy = arcpy.mapping.Layer(r"Database Connections\ims to plainfield.sde\gisedit.DBO.MGU_Will\gisedit.DBO.Address_Points")
street = arcpy.mapping.Layer(r"Database Connections\ims to plainfield.sde\gisedit.DBO.MGU_Will\gisedit.DBO.Street")
outFeature1 = "WillCounty_AddressPoints"
outFeature2 = "WillCounty_Streets"
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "gisedit.DBO.Address_Points", df):
arcpy.mapping.RemoveLayer(df, lyr)
print "removed: {}".format(lyr)
arcpy.mapping.AddLayer(df, addy, "TOP")
print "added: {}".format(addy)
arcpy.FeatureClassToFeatureClass_conversion(addy, ws, outFeature1)
print "saved in data folder: {}".format(outFeature1)
for lyr in arcpy.mapping.ListLayers(mxd, "gisedit.DBO.Street", df):
arcpy.mapping.RemoveLayer(df, lyr)
print "removed: {}".format(lyr)
arcpy.mapping.AddLayer(df, street, "TOP")
print "added: {}".format(street)
arcpy.FeatureClassToFeatureClass_conversion(street, ws, outFeature2)
print "saved in data folder: {}".format(outFeature2)
def ZipShapes(path, out_path):
arcpy.env.workspace = path
shapes = arcpy.ListFeatureClasses()
for shapes in shapes:
name = p.splitext(shapes)[0]
zip_path = p.join(out_path, name + '.zip')
zip = zipfile.ZipFile(zip_path, 'w', compression=zipfile.ZIP_DEFLATED)
zip.write(p.join(path,shapes), shapes)
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()
def append2Zip(zipfolder, path):
print 'Appending to ' + zipfolder
zf = zipfile.ZipFile(zipfolder, mode= 'a')
try:
zf.write(path, os.path.basename(path))
finally:
zf.close()
path = r'\\gisfile\GISstaff\Jared\Python Scripts\Data\Disclaimer - Final.txt'
zipfolders = [r'Z:\Data\WillCounty_AddressPoints.zip', r'Z:\Data\WillCounty_Streets.zip']
for zipfolder in zipfolders:
append2Zip(zipfolder, path)