How to check for empty values in fields of *multiple* shape files?

556
1
04-03-2020 08:49 AM
EmtiajHoque1
New Contributor

I have one main folder and it has multiple sub-folder. Each sub-folder has one shapefile. I want to test all fields of the shape file which are having null values. If shape files filed have null values then print the shape file name along with field name.

I have written a code but it only works for one shape file.

import arcpy fc = r'C:\Y4YK\Muni\WX.shp'
fields = dict((f.name, []) for f in arcpy.ListFields(fc) if not f.required) 
rows = arcpy.SearchCursor(fc,"","","","")
for row in rows:    
      for f in fields.keys():        
            fields[f].append(row.getValue(f))     
      for field, values in fields.iteritems():        
           if any(map(lambda s: s is None or not str(s).strip(), values)):           
                print 'Field: "{}" has empty values'.format(field)
0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus

like walk through the folders, listing the featureclasses (shapefiles) and run your function on it?

Walk—Data Access module | Documentation 

You add that to your current code

0 Kudos