[GIS] Calculating Field based on name of shapefile

arcgis-10.1arcgis-desktopfield-calculatorpython-parser

I have multiple shapefiles to which I have added a field called "gname1". For each shapefile, I want "gname1" to be set to the name of that particular shapefile, for every feature within the shapefile. I realize there are multiple ways to do this, but I want to know how to do this within the "Field Calculator" tool. So, in the "gname1=" box under Field Calculator, what is the expression I use to denote that I want the field to be set to the shapefile name?

I am very new to python, and not entirely familiar with the procedure for using python scripts to calculate fields through this tool in Arc10. I have seen other questions similar to this one, but I was confused on how to do this within the field calculator tool.

Best Answer

If you're committed to using the Field Calculator tool your best bet may be a very short python script within the "Pre-Logic Script Code":

def listShpName(yourShp):
  desc=arcpy.Describe(yourShp)
  return desc.Name

...and then your expression will be

listShpName("LayerInArcMapToC") 

Where LayerInArcMapToC is the name of your layer in ArcMap

I've attached a screen capture to illustrate this. Of course, you'll have to do this on a shapefile-by-shapefile basis if you want to use field calculator. Here's a link to the ESRI documentation on describing data like I've illustrated above: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000018000000

An additional link to some simple field calculator operations: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000

enter image description here