Hi all,
I'm working to create a python script in Arcpro notebooks to add the filepath of a PDF document associated with each attribute in a table to a new field in that same table.
The issue is that the PDF documents are in different folders (layout shown below):
MAINFOLDER
A
STREETNAME1
ADDRESS1.pdf
ADDRESS2.pdf
STREETNAME2
STREETNAME3
B
STREETNAME1
ADDRESS1.pdf
ADDRESS2.pdf
STREETNAME2
STREETNAME3
C
...
If all of the PDF documents had the same path, I would just use an updatecursor to add in the path + ADDRESSField. Since the path is different, I'm not sure how to add the correct path to each attribute.
Currently, I've used the glob module to add all of the PDF filepaths to a list, and I have a list of lists that contains the attribute fields for both STREET_NUM and STREETNAME that I'm using to associate each attribute with the correct table.
Code:
import glob
import os
os.chdir('M:\Service Sheets')
servicePath = glob.glob("*/*/*.pdf") # Here is the list of all PDF files in the directory
fc = "Parcel_Subset"
fields = ["STREET_NUM", "STREETNAME", "PDFLink"] # PDFLink is where the output will go
LocList = []
with arcpy.da.SearchCursor(fc, ['STREET_NUM', 'STREETNAME']) as cursor:
for row in cursor:
LocList.append(row) # Creates the List of Lists
# Here would be the updatecursor, if I could get it to work
I'm not sure this is the best method, or if there's an easier way that I just don't know. This would also just add a text field with the path, if possible, it would be better to make the path a clickable link that opened the PDF document.
Any advice or solutions would be appreciated!