I have a few hundred folders, each with a set of shapefiles that are identical across folders (ie each folder has a 'lot.shp'). They are all supposed to be polygon features, but unfortunately many are line features.
I am trying to convert all line features to polygons using Feature to Polygon.
To do this I have tried the following code which should work through each folder converting the desired shapefiles and saving back into the same folder but with a '2' in the name:
import arcpy, glob, os filelist = ['buildingpoly','lot', etc etc] path = "C:/folder_containing_desired_subfolders/*/" for x in filelist: list = glob.glob(path + x + ".shp") arcpy.FeatureToPolygon_management(in_features=list, out_feature_class=path + x + "2.shp", cluster_tolerance="", attributes="ATTRIBUTES", label_features="") del list
But this gets the following error:
Runtime error Traceback (most recent call last): File "", line 10, in File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 2524, in FeatureToPolygon raise e ExecuteError: ERROR 000210: Cannot create output C:/folder_containing_desired_subfolders/*/buildingpoly2.shp Failed to execute (FeatureToPolygon).
Any ideas? I'm at a loss on this one.
An alternative that would also work is if I can have all the new polygon features saved in the same directory but this would require each getting a unique name.
Here is code that works. It works through the folders and converts all polylines to polygons.
import os, sys, arcpy directory = "C:/working_folder/" for path, path_names, data_names in arcpy.da.Walk(directory, type="Polyline"): for data_name in data_names: arcpy.FeatureToPolygon_management(in_features= (os.path.join(path, data_name)), out_feature_class= (os.path.join(path, "two"+data_name)), cluster_tolerance="", attributes="ATTRIBUTES", label_features="")