2

The basic premise is as follows: look in a folder and find all feature classes (within file GDBs), use a for loop to isolate feature classes one at a time and subsequently isolate date attributes, iterate through and update all the date-related attributes to a given value (currently set at 9/9/9999).

The code will run, but nothing happens. The print statements I have embedded won't even return anytihng. I think the error is somewhere up at the beginning.

import arcpy
import os
try:
 def fcs_in_workspace(workspace):
 arcpy.env.workspace = workspace
 for fc in arcpy.ListFeatureClasses():
 yield os.path.join(workspace, fc)
 for ws in arcpy.ListWorkspaces():
 for fc in fcs_in_workspace(os.path.join(workspace, ws)):
 yield fc
 for fc in fcs_in_workspace("path to folder of GDBs"):
 allFields = arcpy.ListFields(fc)
 stringFields = []
 for field in allFields:
 if field.type == "Date" and "flex" not in field.name:
 stringFields.append(field.name)
 print(str(field.name))
 stringCount = len(stringFields)
 with arcpy.da.UpdateCursor(fc, stringFields) as curU:
 for row in curU:
 rowU = row
 for fields in range(stringCount):
 # change below to None or ''
 if rowU[fields] == '':
 rowU[fields] = "9/9/9999"
 elif rowU[fields] == None:
 rowU[fields] = "9/9/9999"
 curU.updateRow(rowU)
 del curU
 print("Updated Dates for " + str(fc))
except Exception as e:
 print("Error: " + e.args[0])
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 28, 2022 at 18:10
3
  • If nothing's being printed then it's not entering the first for loop, meaning fcs_in_workspace() isn't yielding anything. Add some print statements in there, make sure the folder path you're passing in is valid, etc. Commented Apr 28, 2022 at 18:45
  • There's a ton of reasons to use ISO 8601 formatting (e.g. "YYYY-MM-DD") for date strings ob xkcd reference Commented Apr 29, 2022 at 1:54
  • I recommend removing try/except statements while testing and whenever you present code here because they can mask otherwise useful error messages. Commented Apr 29, 2022 at 7:57

1 Answer 1

0

Here's my solution to the first part of your script. Maybe combining this with your UpdateCursor will help? I think you may be grabbing the fields wrong. Let me know if this works! If not, I can do some more debugging tomorrow. FYI the feature classes I was testing didn't have date fields, so I just called String fields instead, so you'll have to change that part of the script.

import arcpy
import os
try:
 workspace = arcpy.env.workspace = r"FOLDER"
 gdb_list = arcpy.ListWorkspaces("*", "FileGDB")
 fc_list = []
 allfields = []
 stringFields = []
 for dirpath, dirnames, datatypes in arcpy.da.Walk(workspace, datatype = "FeatureClass"):
 for i in datatypes:
 fc_list.append(os.path.join(dirpath, i))
 #print (fc_list)
 for feature in fc_list:
 field_list = arcpy.ListFields(feature)
 for field in field_list:
 #print(field.type)
 if field.type == "String":
 stringFields.append(field.name)
 print(stringFields)
except Exception as e:
 print(e)
 print(arcpy.GetMessages())
answered Apr 28, 2022 at 20:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.