Adding file name to attribute field using Calculate Field?
This python code adds FILENAME field to all Featureclasses (excluding those in Datasets) and populates with featureclass name.
# Import standard library modules
import arcpy, os, sys
from arcpy import env
# Allow for file overwrite
arcpy.env.overwriteOutput = True
# Set the workspace directory
env.workspace = r"P:\geodatabase.gdb\filename"
# Get the list of the featureclasses to process
fc_tables = arcpy.ListFeatureClasses()
# Loop through each file and perform the processing
for fc in fc_tables:
print str("processing " + fc)
# Define field name and expression
field = "FILENAME"
expression = str(fc) #populates field
# Create a new field with a new name
arcpy.AddField_management(fc,field,"TEXT")
# Calculate field here
arcpy.CalculateField_management(fc, field, '"'+expression+'"', "PYTHON")
There is a script on the arcscripts website that should assist you in doing this
http://arcscripts.esri.com/details.asp?dbid=14534
Summary A simple script for creating a field called "FILENAME" and attaching the filename of the shapefile to each entry in the attribute table. Use with as many shapefiles within a specified directory. Useful when picking apart shapefile entries and combining into a separate file to maintain a breadcrumb trail of the original shapefile name.
Run file within a directory containing all the shapfiles needing modification
I hope that this's what you're after
Here is a link to an even better and easier tool using model builder.
http://catalog.data.gov/dataset/arcgis-tool-inserts-file-name-into-attribute-table#