I have four folders, each with 50 sub folders. Within each sub folder I have 80 shapefiles. For the first shapefile within each sub folder I want to add a field and populate that field with the name of the sub folder.
I am attempting to do this like so:
import arcpy import os folders=r'F:\Sheyenne\grazing_final\pressure_per_pixel_by_allotment\allotment_points' #path to four folders for folder in os.listdir(folders): for sub in os.listdir(os.path.join(folders,folder)): #path to sub folders arcpy.env.workspace=os.path.join(folders,folder,sub) #set environment shapefiles=[os.path.join(arcpy.env.workspace, i) for i in arcpy.ListFeatureClasses('*.shp')] shapefiles=shapefiles #return only the first shapefile from each sub folder arcpy.AddField_management(shapefiles, "Allotment", "SHORT", "5") #add new field to each shapefile with arcpy.da.UpdateCursor(shapefiles, 'Allotment') as cursor: #populate each field with the string contained in sub for row in cursor: row.setValue(sub) cursor.updateRow(row) del row
but this returns:
File "F:/python codes/prelim_codes/grazing_regression.py", line 78, in <module> row.setValue(allotment) AttributeError: 'list' object has no attribute 'setValue'