Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know there has to be a way to do this but I'm having trouble figuring out how to do so. I would like to create a list of feature classes to perform operations on however, I want to have the list contain feature classes which have 2 separate and distinct file name identifiers. The code would look something like:

FCS = arcpy.ListFeatureClasses("X_*" OR "*_Y")

I know OR is incorrect however, is there some way to do this without having to re write code to work with the second wildcard. Thanks for helping gout, i know there is a selection method in the Select By Attributes which allows for multiple wildcard use using the OR statement.

share|improve this question
The wildcard parameter only takes a string as input, so short of running ListFeatureClasses() twice (which could potentially be too slow for large directories, it's best to pass no wildcard and then just filter through the result after. – Paul Jul 25 '14 at 15:54
Paul, that is exactly what the list comprehension answer below does - it runs through the list and filters it based on the if statement. – dklassen Jul 25 '14 at 15:58
@dklassen, OP is looking for FC that end in "_Y", not start. You can wildcard that against a GDB, but not shapefiles with your code. – Paul Jul 25 '14 at 16:01
up vote 5 down vote accepted

Add the two together, they are just lists.

FCS = arcpy.ListFeatureClasses("X_*") + arcpy.ListFeatureClasses("*_Y")

To eliminate duplicates:

FCS = set(arcpy.ListFeatureClasses("X_*") + arcpy.ListFeatureClasses("*_Y"))
share|improve this answer
This works also, thanks @Jason Sheirer, using startswith and endswith works for me in a file GDB. When I altered the script I was using to work with an SDE, it didn't work for some reason. The method you mentioned does work in SDE. – standard Jul 30 '14 at 16:14

You could approach it a bit differently:

import arcpy
import os

arcpy.env.workspace = 'c:\temp'
fcs = [fc for fc in arcpy.ListFeatureClasses() if fc.startswith('X_') or os.path.splitext(fc)[0].endswith('_Y')]
share|improve this answer
This won't really work unless you are in a GDB. The extension is returned for shapefiles. – Paul Jul 25 '14 at 15:51
This should work for any feature class within your set workspace. Including shapefiles - why wouldn't we want an extension returned? – dklassen Jul 25 '14 at 15:54
Because you can't wildcard with this against ending characters - which is what OP looks to be doing. – Paul Jul 25 '14 at 16:01
@Paul Modified - thanks for the correction. I didn't see the "_Y" part. – dklassen Jul 25 '14 at 16:07
A bit nitpicky, but you should use os.path.splitext(). The shapefile could have a period in the name. +1 – Paul Jul 25 '14 at 16:08

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.