Hello,
I have several folders under one big folder called "Counties". I'm attempting to use arcpy.da.walk to copy features. I'm trying to copy a shapefile called "Parcels" from each folder within the Counties folder. I run the code below and it works on one county folder, but then stops because the name of the shapefile is the same. So I now want to rename them in the same code block. Is this possble? I'd like to attach the name of the parent directory (which is the county name) so the output fc is "Parcels_Anderson", "Parcels_Bedford", etc.
Any help appreciated!
Here is the code:
workspace = "D:/Geodata/Cadastral/Parcels/Counties"
outgdb = "D:/Geodata/Cadastral/Parcels/Parcels_features.gdb"
walk = arcpy.da.Walk(workspace, datatype = "FeatureClass")
for dirpath, dirnames, filenames in walk:
for file in filenames:
infc = os.path.join(dirpath, file)
desc = arcpy.da.Describe(infc)
outfc = os.path.join(outgdb, desc["baseName"])
arcpy.management.CopyFeatures(infc, outfc)