I know a little Python/arcpy, enough to barely get me by. My goal was to, on a regular task schedule, convert feature classes to shapefiles and overwrite existing shapefiles, but I realized that arcpy.overwriteoutput = True did not work. So, as a work around, I added an os remove code to remove all files ending in .shp, .dbf. prj etc. I ran it in ArcCatalog and it was successful in deleting some file types but not all of the file types associated with the shapefile, and although I commanded it to delete .shx, .cbg, and .sbn files, they still remained in the folder. I also tried arcpy.CopyFeatures_management to copy the feature classes to the existing shapefiles in the workspace, but I was unsuccessful in even getting a version of a script to work.
Here is an example of a code that works but runs in an infinite loop.
(I replaced the workspaces, folders, and destinationoutput) Please focus on the infinite for loop.
import os import arcpy dir_name = C:\Users\Employee\Documents\ArcGIS location = os.listdir(dir_name) extensions = (".shp", ".prj", ".dbf", ".xml", ".cpg", ".sbn", ".sbx" ".shx") for item in location: if item.endswith(extensions): os.remove(os.path.join(dir_name, item)) arcpy.overwriteoutput = True arcpy.env.workspace = C:\Users\Employee\Documents\ArcGIS\NSD_exampleschemaCOPY.gdb destinationOutput = C:\Users\Employee\Documents\ArcGIS\HansenTest datasetList = arcpy.ListDatasets() waterfcList = arcpy.ListFeatureClasses("", "", "WaterDistribution") for datasets in datasetList: for fc in waterfcList: if fc in waterfcList: arcpy.FeatureClassToShapefile_conversion(fc, destinationOutput) elif fc == "MST_Temp_Pipeline_Project": break else: arcpy.AddMessage("Complete")
I also tried this to work but it keeps processing with no end in sight:
import arcpy arcpy.env.overwriteOutput=True arcpy.env.workspace = r'C:\Users\Employee\Documents\afgdb.gdb' outWorkspace = r'C:\Users\Employee\Documents\Employee' datasetLists = arcpy.ListDatasets() fcList = arcpy.ListFeatureClasses() cases = ("watertest", "watertest1", "watertest2", "sewertest", "sewertest1", "sewertest2", "sewertest3") for datasets in datasetLists: for shapefile in fcList: for shapefile in cases: outFeatureClass = os.path.join(outWorkspace, shapefile.strip(".gdb")) arcpy.CopyFeatures_management(shapefile, outFeatureClass)
I for some reason couldn't answer my own question, but the script below works without looping infinitely.
import arcpy arcpy.env.overwriteOutput=True arcpy.env.workspace = r'C:\Users\bnamsaly\Documents\New File Geodatabase.gdb' outWorkspace = r'C:\Users\bnamsaly\Documents\Vicky' datasetLists = arcpy.ListDatasets() fcList = arcpy.ListFeatureClasses() cases = ("watertest", "watertest1", "watertest2", "sewertest", "sewertest1", "sewertest2", "sewertest3") for shapefile in cases: try: outFeatureClass = os.path.join(outWorkspace, shapefile.strip(".gdb")) arcpy.CopyFeatures_management(shapefile, outFeatureClass) except arcpy.ExecuteError: tb = sys.exc_info() # execute errors from Python tbinfo = traceback.format_tb(tb) pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()) arcpy.AddError(pymsg) msgs = "ARCGIS ERRORS:\n" + arcpy.GetMessages(2) + "\n" arcpy.AddError(msgs)