I'm looking to add a large number of point files into an .mxd from a huge group of multi-layer folders. The script from Loading multiple shapefiles from +1000 subfolders worked with some tweaks, but doesn't return anything presumably since all of the files have different names after the prefix (i.e. Subject Baltimore / Subject Aberdeen / Subject Rockville etc).
Is there a way to add something to tell the script to look at just the first part of the shapefile's label? here is the code I'm using:
import os
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
workspace = "T:\\GIS\\Special Projects\\ESRI UC MAP 2017\\Maryland" #place the path to your data inside the quote marks, remembering to use forward slashes
feature_classes = []
walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="Point")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
feature_classes.append(os.path.join(dirpath, filename))
for dataset in feature_classes:
dataset = dataset.upper()
if "Subject" in dataset:
add_layer = arcpy.mapping.Layer(dataset)
arcpy.mapping.AddLayer(df, add_layer)