Iterate Feature Classes: (Multiple Wildcards)

5288
3
Jump to solution
02-20-2013 01:30 AM
PeterWilson
Occasional Contributor III
Does anyone have a workaround for me where I can specify multiple wildcards when using "Iterate Feature Classes". I need to search for feature class that have the following tile names within a directory of multiple folder such as 1: 2830* 2: 2831* 3: 2930* and copy the shapfiles (polylines) into a File Geodatabase for futher processing.

Wildcards:

2830*;2831*;2930*


Regards
0 Kudos
1 Solution

Accepted Solutions
AndrewChapkowski
Esri Regular Contributor
Does anyone have a workaround for me where I can specify multiple wildcards when using "Iterate Feature Classes". I need to search for feature class that have the following tile names within a directory of multiple folder such as 1: 2830* 2: 2831* 3: 2930* and copy the shapfiles (polylines) into a File Geodatabase for futher processing.

Wildcards:

2830*;2831*;2930*


Regards


You can create 3 models for each of your cases, and then combine the models into one model.  Or you can try using python, which might be easier.
Your Python code would look like this:
import arcpy
destination = arcpy.GetParameterAsText(0)
workspace = arcpy.GetParameterAsText(1)
arcpy.env.workspace = workspace
cases = ['2830', '2831', '2930']
for fc in arcpy.ListFeatureClasses():
    for case in cases:
        if fc.startswith(case):
           print 'copy the data'


if you want to input your start with text, you could create a multi-value string and then split by ';'.

Hope this gets you on track.

View solution in original post

3 Replies
deleted-user-FYWnb7WVNuhY
New Contributor III
*Bump* I have a need for this also and have not found a solution.
0 Kudos
AndrewChapkowski
Esri Regular Contributor
Does anyone have a workaround for me where I can specify multiple wildcards when using "Iterate Feature Classes". I need to search for feature class that have the following tile names within a directory of multiple folder such as 1: 2830* 2: 2831* 3: 2930* and copy the shapfiles (polylines) into a File Geodatabase for futher processing.

Wildcards:

2830*;2831*;2930*


Regards


You can create 3 models for each of your cases, and then combine the models into one model.  Or you can try using python, which might be easier.
Your Python code would look like this:
import arcpy
destination = arcpy.GetParameterAsText(0)
workspace = arcpy.GetParameterAsText(1)
arcpy.env.workspace = workspace
cases = ['2830', '2831', '2930']
for fc in arcpy.ListFeatureClasses():
    for case in cases:
        if fc.startswith(case):
           print 'copy the data'


if you want to input your start with text, you could create a multi-value string and then split by ';'.

Hope this gets you on track.
KONPETROV
Occasional Contributor III

your code saved me, very nice

0 Kudos