-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-date-fields.py
33 lines (26 loc) · 1.03 KB
/
add-date-fields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# modules
import arcgisscripting, os, sys
# geoprocessing object
gp = arcgisscripting.create(9.3)
#loop through the directory
for root, dirs, files in os.walk("C:\\###\\###"):
for name in files:
gp.workspace = root #workspace
date = name[10:18] #grabs date
hypen = "-"
hyphen_date = date[0:3] + hyphen+date[3:5] + hyphen + date[5:7] #add hyphensto date
if name[name.rfind("."):len(name)] == ".shp": #get shapefiles
print "adding field for this shapefile: " + name
gp.addfield(name,"starting_date","DATE") # Add a datefield
# update each row with the current date
try:
rows = gp.UpdateCursor(name)
row = rows.Next()
while row:
row.start_date = hyphendate
rows.UpdateRow(row)
row = rows.Next()
del row, rows
except:
if not gp.GetMessages() == "":
gp.AddMessage(gp.GetMessages(2))