I'm having an issue where calling arcpy.ListFeatureClasses()
in a workspace with 400 shapefiles takes a very long time (more than 10 minutes).
Using the os
module to achieve the same effect takes less than a second:
import os
allSingleNonRoadPolys = []
for file in os.listdir(r'D:\data\allSingleNonRoadPolys'):
if file.endswith(".shp"):
print(file)
allSingleNonRoadPolys.append(file)
You can then achieve the same effect as ListFeatureClasses
by simply prepending the workspace to the filename, each time you need to use a dataset, as seen here:
for shp in allSingleNonRoadPolys:
arcpy.someTool(workspace + '\\' + shp)
Why would I even keep using ListFeatureClasses()
and what makes it take so long? Does it do anything incredibly useful that cannot be achieved in any other way?
ListFeatureClasses()
is especially good at listing feature classes in an Esri geodatabase. You may want to look into theglob
module too, which has very nifty (and efficient) ways of listing data:shps = glob.glob(r'D:\data\allSingleNonRoadPolys\*.shp')