AnsweredAssumed Answered

Where to incorrporate IF and Else if file doesnt exist after os.walk? Python Question.

Question asked by Brian_J91 on Mar 6, 2016
Latest reply on Mar 7, 2016 by wwmiller68

I am extremely new to python so any help would be greatly appreciated. How would you skip the arcpy.Merge and arcpy.Clip if 'AAA010.shp' does not exist in the directory that os.walk is going through. I will have more code after the last line in this snippet. Currently, the script just skips completely over the 'AAA010.shp' even though it exists.

 

import os, fnmatch, arcpy

arcpy
.env.workspace  =  rC:\Users\sysadmin\desktop\datamanagement\MGCP.gdb

fcMerged
= MergedFeatureClass

fcClipped
= ClippedFeatureClass

fcToClip
= rC:\Users\sysadmin\desktop\datamanagement\Country.shp

filesMatched
= list()

for root, subfolders, files in os.walk(rC:\Users\sysadmin\desktop\datamanagement\MGCP_Raw’):

 
for f in fnmatch.filer(files, AAA010.shp’):
  filesMatched
.append(os.path.join(root,f))

if 'AAA010.shp' in filesMatched:

  arcpy
.Merge_management (filesMatched, fcMerged)

  arcpy
.Clip_analysis (fcMerged, fcToClip, Extraction_Mine)

else: pass

Outcomes