import arcpy, os, fnmatch #for wildcards from arcpy import env rootDir = r"FILEPATH_IS_HERE" for dirPath, dirNames, fileNames in os.walk(rootDir):#, topdown=False): for file in fileNames: if fnmatch.fnmatch(file, "*100110.shp")== True: print os.path.join(dirPath, file) env.workspace = os.path.join(dirPath, file) arcpy.Buffer_analysis(file, r"FILEPATHGOESHERE", 1000) else: print "No other matching 100110's"
Solved! Go to Solution.
import arcpy, os, fnmatch #for wildcards from arcpy import env rootDir = r"FILEPATH_IS_HERE" ourDirName = "outputFolder" buffShape = "outputBuffer.shp" for dirPath, dirNames, fileNames in os.walk(rootDir):#, topdown=False): for file in fileNames: if fnmatch.fnmatch(file, "*100110.shp")== True: print os.path.join(dirPath, file) env.workspace = os.path.join(dirPath, file) arcpy.Buffer_analysis(file, rootDir + os.sep + outDirName + os.sep + buffShape, 1000) else: print "No other matching 100110's"
for dirPath, dirNames, fileNames in os.walk(rootDir):#, topdown=False): for file in fileNames: if fnmatch.fnmatch(file, "*100110.shp"): shpname = os.path.join(dirPath, file) arcpy.Buffer_analysis(shpname, r"FILEPATHGOESHERE", 1000)
What's the error message it's returning? Have you tried it without the workspace tweaking?
import arcpy, os, fnmatch #for wildcards from arcpy import env rootDir = r"FILEPATH_IS_HERE" ourDirName = "outputFolder" buffShape = "outputBuffer.shp" for dirPath, dirNames, fileNames in os.walk(rootDir):#, topdown=False): for file in fileNames: if fnmatch.fnmatch(file, "*100110.shp")== True: print os.path.join(dirPath, file) env.workspace = os.path.join(dirPath, file) arcpy.Buffer_analysis(file, rootDir + os.sep + outDirName + os.sep + buffShape, 1000) else: print "No other matching 100110's"
import arcpy, os, fnmatch #fnmatch for wildcards
from arcpy import env
rootDir = XXXXX
vt = arcpy.CreateObject("ValueTable")
for dirPath, dirNames, fileNames in os.walk(rootDir):
for file in fileNames:
if fnmatch.fnmatch(file, "*AddedNew*.shp")== True: #iterates for files with AddedNew in name
env.workspace = os.path.join(dirPath) #tells where to look for input feature
shps = arcpy.ListFeatureClasses("*", "Polygon")
print shps
for shp in shps:
vt.addRow(shp)
featureOut = os.path.dirname(dirPath) + "Statewide_NewCoverage" # Finds area of beginning iteratiom + Name of outputfeatureclass
arcpy.Merge_management(vt,featureOut)
else:
print "Merge New Coverage files has failed"