Saya memiliki alat skrip berguna yang loop melalui ruang kerja dan mengubah nama dan menyalin shapefile ke dataset fitur. Namun, jika ada shapefile rusak di suatu tempat di ruang kerja skrip gagal dan berhenti diproses.
Bagaimana Anda menangani kesalahan seperti ini? Apakah ada cara untuk mencetak file kesalahan dan melanjutkan memproses shapefile berikutnya dalam for loop sampai selesai?
import arcpy
from arcpy import env
# Allow overwriting of output
env.overwriteOutput = True
# Parameters
env.workspace = arcpy.GetParameterAsText(0)
state = arcpy.GetParameterAsText(1)
gdb = arcpy.GetParameterAsText(2)
# Get a list of shapefiles in folder
fcs = arcpy.ListFeatureClasses()
# Find the total count of shapefiles in list
fcCount = len(fcs)
# Set the progressor
arcpy.SetProgressor("step", "Copying shapefiles to geodatabase...", 0,fcCount, 1)
# For each shapefile, copy to a file geodatabase
try:
for shp in fcs:
# Define name for the output points
fc = str(state + shp[0:9])
# Update the progressor label for current shapefile
arcpy.SetProgressorLabel("Loading " + shp + "...")
# Copy the data
arcpy.CopyFeatures_management(shp, str(gdb + "\\" + fc))
# Update the progressor position
arcpy.SetProgressorPosition()
except Exception as e:
print "An error has occurred"
print e
arcpy.ResetProgressor()