import arcpy import os fc = r" C:\Users\GIS\Documents\TEST 2-25\project_test.shp" fields = ["PROJECT_DW"] with arcpy.da.SearchCursor (fc,fields) as cursor: for row in cursor: Roll = str(row[0]) if os.path.exists(Roll): pass else: f = open(r"C:\Users\GIS\Documents\brokenlinks.txt","a") f.write(Roll + os.linesep) f.close()
Forgot to add, also tried James idea and still all showed up.
Roll = "H:\\exists\\broken\\dfBA D.csv"
if os.path.exists(Roll): print "roll exists: " + Roll else: print "roll failed"
Well, I added a new field and recalculated it so all \ became \\. Still, every single hyperlink showed up on my text file when I ran the original code after doing that (and I did change the field name). So not sure where to go from here.
import arcpy import os fc = r" C:\Users\GIS\Documents\TEST 2-25\project_test.shp" fields = ["PROJECT_DW2"] toTxtFile="" with arcpy.da.SearchCursor (fc,fields) as cursor: for row in cursor: Roll = str(row[0]) if os.path.exists(Roll): pass else: toTxtFile+=Roll + os.linesep #write to file f = open(r"C:\Users\GIS\Documents\brokenlinks.txt","w") #note that "w" will overwrite the file if it already exists f.write(toTxtFile) f.close()
import arcpy import os fc = r"C:\Users\GIS\Documents\TEST 2-25\project_test.shp" fields = ["PROJECT_D2"] toTxtFile="" with arcpy.da.SearchCursor (fc,fields) as cursor: for row in cursor: Roll = str(row[0]) if not os.path.exists(Roll): toTxtFile+=Roll + os.linesep #write to file f = open(r"C:\Users\GIS\Documents\brokenlinks.txt","w") #note that "w" will overwrite the file if it already exists f.write(toTxtFile) f.close()
os.path.exists(r"F:\Lp04\PROV NORTHGLEN\DWG\SHEET 1.DWG")
os.path.exists(r"F:") os.path.exists(r"C:")
2. tested true (also tried a fake hyperlink which tested false)
os.path.exists(r"F:\Lp04\PROV NORTHGLEN\DWG\SHEET 1.DWG")
os.path.exists("F:\Lp04\PROV NORTHGLEN\DWG\SHEET 1.DWG")
os.path.exists("F:\\Lp04\\PROV NORTHGLEN\\DWG\\SHEET 1.DWG")
os.path.exists("F:/Lp04/PROV NORTHGLEN/DWG/SHEET 1.DWG")