import os, fnmatch, arcpy arcpy.env.workspace = r'C:\Users\sysadmin\Desktop\DataMagement\Comp_3\SA_MGCP3.gdb' fcToClip = r'C:\Users\sysadmin\Desktop\DataMagement\SA.shp' # For each name for shapefileName in ('AAA010', 'LAQ075', 'OtherRandomName'): # Initialize an empty list that will store the paths to shapefiles filesMatched = list() # Recursively search through all subdirectories under 'MGCP_Raw' for root, subfolders, files in os.walk (r'C:\Users\sysadmin\Desktop\DataMagement\MGCP_Raw'): # In the current subdirectory, get a list of any shapefiles in it that match the current name for f in fnmatch.filter(files, '{}.shp'.format(shapefileName): # Add that shapefile's path, if it exists, to the tally list of shapefile paths filesMatched.append(os.path.join(root,f)) # If there are any shapefiles in the list if len(filesMatched) > 0: # Set the paths for our output feature classes - they will be named the same as our search # string, along with an underscore and a description of what's been done to it fcMerged = '{}_Merged'.format(shapefileName) fcClipped = '{}_Clipped'.format(shapefileName) # Merge and then clip the features arcpy.Merge_management(filesMatched, fcMerged) arcpy.Clip_analysis(fcMerged, fcToClip, fcClipped)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question