2

I have a dBase table that has a field containing file paths. Within this field there are over 1,000 records. I created a list, using a search cursor, that contains all the file paths. An example of an element in the list is C:\TestFolder\Folder1\A\address_pt.shp

I want to pass this list to the arcpy.Exist function one by one to see if the shapefile exists within the defined workspace.

The code that I currently have only creates a list and prints out the items in the list.

import arcpy
arcpy.env.workspace = r"define directory for arcpy.Exist to look in"

#Set variables:

myLayer = "define the dbf path"
myField = "APFILE_PATH"

myList =[row[0] for row in arcpy.da.SearchCursor(myLayer,myField)]
#print(myList)


for item in myList:
    print (item)
#Insert Arcpy.Exist somewhere in this for loop?

I am new to python and arcpy and I'm not sure how to structure the for loop to take an element out of the list, one by one, and insert it into the arcpy.Exist function to see if the shapefile exits.

Ideally, I want to see if the shapefile exists, based on the file path, and if it exists I want to mark it as a Yes or a No, possibly within a new field within the existing dbf file. Also, if the shapefile exists, I will eventually pass it along to another function that will check if fields exist within the shapefile. However, for now, i'm just working on understanding and coding the first part to see if the shapefile exists.

I'm not sure if this is even possible with the arcpy.Exist function. I'm taking this process step by step.

5

You can simply do:

for item in myList:
    if arcpy.Exists(item):
        # do something, e.g.
        print("{} exists".format(item))
    else:
        print("{} does not exist".format(item))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.