I have a list object that contains file paths as text. I named the list object filepathlist. An example of a file path within the list is C:\TestFolder\Folder1\A\address_pt.shp. The file paths lead to a directory where some folders contain shapefiles.
I want to use the list object,filepathlist, and iterate through each element of the list passing the list into the arcpy.ListFields function to create multiple lists of field names for each shapefile. I'm not sure if it's possible, but maybe even a list containing multiple lists within.
I want to create lists of Field names for each shapefile in my directory because I ultimately plan to use the list of fields generated from the arcpy.ListFields function and compare the lists to another list that contains field names thought to be within the shapefile. I aim to ultimately solve the problem and question:
Does my list of fields found in the shapefile match the list of fields thought to be within the shapefile?
However, my question and first problem is trying to figure out the logic and code of how to iterate through a list of file paths within the arcpy.ListFields function and return lists of Fields within each shapefile.
I'm not sure if i'm taking the right approach in trying to solve the problem. I have included code below to try and explain what i'm trying to do.
import arcpy arcpy.env.workspace = r"C:\TestFolder" #dbf File Process control Table dbf = "ProcessControlTable.dbf" #File Path of shapefile shapefile = "C:\\TestFolder\\Folder1\\F1\\address_pt.shp" #Define Field within dBASE Table that holds File Paths myfield = "FI_PATH" #Print List of Field Names for shapefile defined print([field.name for field in arcpy.ListFields(shapefile)]) #List of file paths with list comprehension filepathlist =[row for row in arcpy.da.SearchCursor(dbf,myfield)] print(filepathlist) #Use arcpy.ListFields function to iterate through filepaths list lstfields = arcpy.ListFields(filepathlist) for row in lstFields: #Create a list of Field Names for each Shapefile found in filepathlist #Save the field names object list for each shapefile so it can be compared to another list #Print a list of Field Names in each Shapefile
Basically, I only know how to list the fields from one shapefile. I would like some guidance on where I can take the logic and code to possibly iterate through a list of file paths and list fields for each shapefile at the path location.