import arcpy,os
# delete old zips
def delete_old_parcels_zip(oldzip, workspace_folder):
arcpy.env.workspace = workspace_folder
# r=root, d=directories, f=files
for root, directories, files in os.walk(workspace_folder):
for file in files:
if file.endswith(oldzip): #.endswith accepts a tupule
#delete existing zips from folder
print("old zips deleted: {}".format(file))
arcpy.AddMessage("old zips deleted: {}".format(file))
arcpy.Delete_management(file)
if __name__ == "__main__":
#name of zip file with extension
oldzip = arcpy.GetParameterAsText(0)
# output folder
workspace_folder = arcpy.GetParameterAsText(1)
# delete
delete_old_parcels_zip(oldzip, workspace_folder)
I'm having trouble getting this script to work as a script tool. It works fine as a stand-alone. I've tried a number of things in Pro Catalog Toolboxes:
- Properties > Execution panel > embedded
- Properties > Execution panel > external script
- Properties > Parameter 0: Data Type > File > Filter File (zip; shp)
- Properties > Parameter 0: Data Type > Shapefile
- Properties > Parameter 0: Data Type > Folder
- Properties > Parameter 1: Data Type > Workspace
It doesn't throw any errors. But it produces no results. Basically, the tool is supposed to find a file based on user input and in the workspace and delete it. Note: I'm after learning to use if __name__ == "__main__" in a script tool.