Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Script to populate file name field not working with update to 10.2.1

$
0
0
Hello everyone,

I had a script that added a field and populated it with the file name. In this case the files are .DBF. The only thing that has changed is our update to 10.2.1. Here is the code that previously worked:
Code:

import arcpy
from arcpy import env

###### =====================================================================
#### Select Attributes - add FileName field

print "Adding FileName field ... "

#### Sets new arcpy environment
env.workspace  = "C:\\directory"
tablist = arcpy.ListTables("","dBASE")
print 'tablist:',tablist
# counter for appending filename to DBF
cnt = 0

# codeblock for CalculateField function
codeblock = """
def customListReplacer(cnt):
        row = tablist[cnt]
        return row"""

## Loop that adds FileName field
for tables in tablist:
        arcpy.AddField_management(tables, "FileName","TEXT")
        arcpy.CalculateField_management(tables, "FileName","customListReplacer(cnt)","PYTHON",codeblock)
        cnt+= 1


Here is the problem: previously the 'cnt' read through the 'tablist' and populated the dbf with the correct file name. Now, this script populates the FileName field with the first DBF in the directory. As a result, every DBF has the first DBF listed in the FileName field.

Any suggestions would be GREATLY appreciated. Thanks!

Viewing all articles
Browse latest Browse all 2485

Trending Articles