May-12-2017, 03:45 PM
(May-12-2017, 03:39 PM)babakkasraie Wrote: Hello
How can I search my shapefiles using python codes to find all shapefiles that start with for instance "landuse" and show the results in a message box?
I used the following code but they return nothing.
Would you have a look on them and remind me about errors?
Thanks for help.
my code here# import arcpy module
import arcpy
import sys
from arcpy import env
import os
import fnmatch
#the list of variables all hard coded to decrease errors
# Set the workspace for ListFeatureClass functions
env.workspace = "C:/GIS_database/module5/module5data.mdb"
# set the variables
# path to the shapefiles
folder = "C:/GIS_database/module5/module5data.mdb"
# Looking for all files starting with landuse and a wildcard *
pattern = 'landuse*.shp'
# This is a master shapefile
filename = "C:/GIS_database/module5/land_use_merged.shp"
# This is the list of shapefiles starting landuse
shpList = []
# add file names to shpList.
for path,dirs,files in os.walk(folder):
for filename in fnmatch.filter(files, pattern):
shpList.append(os.path.join(path, filename))
# Add all names stored in shpList to a message box
for fc in shpList:
arcpy.AddMessage(fc)
You need to use ctrl + shift + v to paste code between python code blocks