Hi All,
I'm new to python and have created the code below after much googling. I'm trying to search through all subfolders within my directory and find all aprx's then list all of the features held within the aprx. My code achieves this but I'd like to make it more efficient by skipping over sub-folders that contain a certain sub-string.
For example I'd like to be able to remove all folders containing the string "myfolder" if the directory contained the following folders:
myfolder_1
myfolder2
testfolder
So my goal would be to only search for aprx's in the folder "testfolder".
My Code:
extensions = ('.aprx')#extention to search
exclude_directories = set(['Archived','#Archived','Archive','archived','archive','#archived','#archive','ss','SS']) #directory (only names) want to exclude
for dname, dirs, files in os.walk(r'C:\Users\MyDirectory'):
dirs[:] = [d for d in dirs if d not in exclude_directories] # exclude directory if in exclude list
for fname in files:
if(fname.lower().endswith(extensions)): #check for extension
fpath = os.path.join(dname, fname) #this generates full directory path for file
aprx = arcpy.mp.ArcGISProject(fpath)
for m in aprx.listMaps():
for lyr in m.listLayers():
if lyr.isBroken:
print("(BROKEN) " + lyr.name + " - " + m.name)
else:
if lyr.supports("DATASOURCE"):
print ("Map Layer Name: " + lyr.name + "| SZ_gis_dataname: " + lyr.dataSource[211:])
