I put your code in a debugging template found on this page: Debugging a ToolValidator class. I only made a few changes, mostly using self.params[0], etc. to access the parameters. I kept the MakeTableView because it aided in identifying the field types. It might be possible to read the text file's first line directly to get the field names, and the second line to determine field types. Print statements will work in the debug script, but they will not display once it is placed in the tool's validator section (and could cause errors). For this reason, they have been commented out.
My first tool parameter was a folder type, the second was a string (for the field names). Here's my debug test code:
import arcpy
arcpy.ImportToolbox(r"C:\Path\to\tool\box\dropdown.tbx")
params = arcpy.GetParameterInfo("DropdownTest")
params[0].value = r"C:\Users\Randy\Documents\ArcGIS\PythonScripts\test\text2field\encoding"
params[1].values = [ 'pH', 'Chl_A (\xb5g/L)' ]
class ToolValidator(object):
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if self.params[0].altered:
if self.params[0].value:
arcpy.env.workspace = filedir = self.params[0].value
list_of_files = arcpy.ListFiles("*.txt")
firsttable=list_of_files[0]
complete_filename = str(filedir)+"\\"+firsttable
if arcpy.Exists("kivu_tview"):
arcpy.Delete_management("kivu_tview")
table=arcpy.MakeTableView_management(complete_filename, "kivu_tview")
desc = arcpy.Describe(table)
fieldselectlist=[]
for ofields in desc.fields:
ftype=ofields.type
fname=ofields.name
if ftype in ["Double","Integer","Long"]:
if fname not in ["Profile_No","Longitude (degrees_east)","Latitude (degrees_north)","Bot. Depth (m)","Depth (m)"]:
with arcpy.da.SearchCursor(table, fname) as calcursor:
for calcrow in calcursor:
if calcrow[0] is not None:
fieldselectlist.append(fname)
break
arcpy.Delete_management("kivu_tview","Table View")
try:
if self.params[1].values:
oldValues = self.params[1].values
except Exception:
pass
self.params[1].filter.list = sorted(fieldselectlist)
newValues = self.params[1].filter.list
try:
if len(oldValues):
self.params[1].values = [v for v in oldValues if v in newValues]
except Exception:
pass
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
validator = ToolValidator()
validator.updateParameters()
validator.updateMessages()
print(arcpy.GetMessages())
print u"Folder: {}".format(params[0].value)
print u"Fields: {}".format(params[1].values)
Once I was happy with the debug test, I pasted the ToolValidator section into the tool's validator.
Hope this helps.