I am trying to get my script to loop through a folder of shapefiles and a folder of gdbs. I need it to compare the name of the shapefiles and gdbs and if they match to continue on to loop through the dataset then feature class of the gdb.
Currently I am trying to set the environment to the current gdb the loop is on as shown in line 29. This gives me the error: 'NoneType' object is not iterable... referring to line 34, "for ds in datasets:"
If I hard code the environment to a gdb folder path instead to test it out, the the script runs but skips over lines 34 to 37.
import arcpy
import os
arcpy.env.overwriteOutput = True
directoryPath = r"C:\Test\ShapefileAOI"
workspace = r"C:\Test\Geodatabase"
for path, dirc, files in os.walk(directoryPath):
for aoi in dirc:
split = os.path.splitext(aoi)
#print(split)
firstSplit = os.path.splitext(aoi)[0]
#print('AOI ' + firstSplit)
for path, dirs, files in os.walk(workspace):
for d in dirs:
splitGdb = os.path.splitext(d)
firstSplitGdb = os.path.splitext(d)[0]
#print('gdb ' + firstSplitGdb)
environment = d
if firstSplitGdb == firstSplit:
print (firstSplitGdb + " shapefile matches " + firstSplit + " gdb")
# set the workspace to the gdb path
arcpy.env.workspace = environment
datasets = arcpy.ListDatasets(feature_type='feature')
for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
path = os.path.join(arcpy.env.workspace, ds, fc)
print(path)
else:
print(firstSplitGdb + " shapefile does NOT match " + firstSplit + " gdb")
if datasets:
before iterating.