Select to view content in your preferred language

Code block to get filepath of shapefile in field calculator

2789
1
03-09-2011 08:14 PM
wilfredwaters
Regular Contributor
Does anyone know a python codeblock to input the filepath of a shapefile in a field using field calculator?

I'll be merging a whole lot of shapefiles later and it would be good to keep track of each record in manner.

Wil
Tags (2)
0 Kudos
1 Reply
FreddieGibson
Honored Contributor

You should be able to calculate this without using a python codeblock. It should be as simple as putting the path to the shapefile in quotes as follows:

r"C:\Path\To\Shapefile.shp"

I would think that you'd want to first calculate this on all of your shapefiles prior to running the merge tool. This could be done by doing the following:

1. Use the arcpy.da.walk or arcpy.ListFeatureClasses methods to locate the shapefiles on disk.

2. For each shapefile found check to see if it has the field that will be storing the path, if not add this field.

3. In the field calculate pass the path to the feature class surrounded by quotes to persist this information in the field.

Let me know if this helps.

0 Kudos