Using user input argument as a wildcard in ListFeatureClasses

871
3
Jump to solution
06-30-2020 08:47 AM
WilliamHerzig
New Contributor

Hello,

I am working on a script that will allow the user to create a list of feature classes, in a directory, where the wildcard is set by a user input argument (sys.argv[2]).  But, I cannot figure out how to get the argument into the optional parameters (between the two asterisks).  Here is the code that I am working on:

import arcpy, os

arcpy.env.workspace = sys.argv[1]

arcpy.env.overwriteOutput = True


sub = sys.argv[2]

fileList = arcpy.ListFeatureClasses('**')

Edited because I just figured out how to insert code.

Thanks,

Bill

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Assuming sub is a string already:

fileList = arcpy.ListFeatureClasses('*' + sub + '*')

or

fileList = arcpy.ListFeatureClasses('*{}*'.format(sub))

View solution in original post

3 Replies
JoshuaBixby
MVP Esteemed Contributor

Assuming sub is a string already:

fileList = arcpy.ListFeatureClasses('*' + sub + '*')

or

fileList = arcpy.ListFeatureClasses('*{}*'.format(sub))
WilliamHerzig
New Contributor

Joshua,

Thanks so much that worked perfectly, I had tried the format, but had it located incorrectly. 

This was how I had tried it -

fileList = arcpy.ListFeatureClasses('*{0}*').format(sub)

0 Kudos
MICHELLESTEPHENS
New Contributor

Thank you!!! Could not figure out how to do this.

0 Kudos