Checking for number of shapefiles in directory using Python?

المشرف العام

Administrator
طاقم الإدارة
I want to test:

  1. to see whether or not ONE AND ONLY ONE shapefile (which will be based on a filename wildcard) exists in a directory.
  2. Add these shapefiles to a list
  3. Use this list variable as an input to merge_managment function.
I already know how to walk through directories and pick out those filenames but not how to do the above.

I was thinking something like:

rootDir = "\homePath"featureinput1 = "path"newOnlyShpList = []for dirPath, dirNames, fileNames in os.walk(rootDir): for file in fileNames: if fnmatch.fnmatch(file, "*" + "2012" + "*" + ".shp")== True ##AND IF ONE SHAPEFILE EXISTS BY ITSELF IN DIRECTORY:## ##append to newOnlyShpList arcpy.Merge_managment([featureinput1, newOnlyShpList], "OutputHere") elif ##ignore if greater than one shapefileAll I know about is the arcpy .exists function but all that does is return a boolean on whether any shapefile exists. Maybe I need to check just for 1 .shp extension and it has nothing to do with arcpy?



أكثر...
 
أعلى