swcagis

if filename in list - why doesn't this work?

Discussion created by swcagis on Aug 7, 2013
Latest reply on Aug 7, 2013 by swcagis
Hi, I'm a python n00b so please be gentle.

I am trying to do a Walk through a directory with many sub directories and I want to search for features (either FC or SHP) whose name matches a choice from a list. Here is part of the code in question.

archDir = ["ARCHIVE", "archive", "Archive"]
matchList = ["SAB", "APE", "StudyAreaBoundary", "StudyArea", "ProjectArea"]

for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace,topdown=True,datatype="FeatureClass",type="Polygon"):
        # disregard any folder named "ARCHIVE" in creating list; as far as I know this works great
        for arch in archDir:
            if arch in dirnames:
                dirnames.remove(arch)

        for filename in filenames:
            # this is the part that isn't working
            if filename in matchList:
                print os.path.join(dirpath, filename)


In my test directory I have two subdirectories that in turn contain various amounts of subdirectories that eventually drill down to the feature in question (in this case an APE feature class in one and an SAB shapefile in the other - they exist at different directory tree levels). With the above script, only the APE feature class is being listed/printed. Any ideas what I'm doing wrong? Does it just not work this way?

Outcomes