Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a similar issue to these threads:

How to list feature classes in multiple geodatabases in a folder?

How to list Feature Classes of Multiple geodatabase in Multiple Folder?

However, I want to search through multiple folders/directories for any feature (FC in an FD, FC in a GDB, shapefile) that has a name that matches a wildcard search (i.e. any of the above features that has a name like ABC*). I would then like to either copy the feature (if it is a feature class) or convert to a FC (if it is a SHP). Bonus if I could rename the copied feature to part of the name of it's original parent directory (i.e. a project number).

For example:

123_Folder --> contains gdb with FC "ABCDE"

456_Folder --> contains folder XYZ with shp "ABCFGHI"

789_Folder --> contains folder LKJ with GDB "KJFSL" with FD "IKESHL" with FC "ABC"

I would love to end up with a gdb that contains: 123_ABC, 456_ABC, 789_ABC, etc.

I'm guessing I need to break this down into multiple search iterations?

I am only a beginner scripter, but learn quickly. Thanks for any help!

Edit: I now have this:

import arcpy, os
#Set the workspace
workspace = r"C:/temp"
#create list of files from directories and subdirectories
for root, dirs, files in arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon"):
    for name in files:
        if name.startswith("ABC") or name.startswith("DEF"):
            path = os.path.abspath(os.path.join(root, name))
            print path

It works great! What I'd like to do now is convert each one to a centerpoint and append to a feature class I already have set up. However, I'd like to exclude any poly that was found in an Archive folder. That is, if the word "Archive" shows up in the path name I want to skip over it. How can I program that in Python?

share|improve this question
I would start with reviewing arcpy.da.Walk which will "walk" you through multiple folders - perhaps get that working to just list what's in each folder and separately look into Python string substitution and concatenation. Once you know how each works start to combine them. –  PolyGeo Jul 30 '13 at 21:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.