Script Property Value list referencing a filename list in a directory

524
2
Jump to solution
08-30-2012 03:31 PM
andrewtucker
New Contributor
Is there anyway that my value list for a sys.argv could be a dynamic list of filenames from a directory?

I want the user to be able to only select files that exist and automatically include new files to the list as I create them.

The filename forms part of an appended text file that is ude by an external process.

Thanks in advance

Andrew Tucker
HVP Plantations
Victoria
Australia
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Hi Andrew,

If you are using your script within a toolbox you can do this using the Tool Validation tab.  You would set a parameter (i.e. Input) under the Parameters tab of the script's Properties.  The Data Type for this parameter would be 'String'.  You can then update the initializeParameters function with the following:

def initializeParameters(self):     arcpy.env.workspace = r"C:\temp\python\test.gdb"     list = []     lstFCs = arcpy.ListFeatureClasses("*")     for fc in lstFCs:        list.append(fc)     stringFilter = self.params[0].filter     stringFilter.list = list     return


You will want to change the 'arcpy.env.workspace' to your desired workspace.  You will also need to update 'arcpy.ListFeatureClasses' if you are working with another data type (i.e. rasters, tables).

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Andrew,

If you are using your script within a toolbox you can do this using the Tool Validation tab.  You would set a parameter (i.e. Input) under the Parameters tab of the script's Properties.  The Data Type for this parameter would be 'String'.  You can then update the initializeParameters function with the following:

def initializeParameters(self):     arcpy.env.workspace = r"C:\temp\python\test.gdb"     list = []     lstFCs = arcpy.ListFeatureClasses("*")     for fc in lstFCs:        list.append(fc)     stringFilter = self.params[0].filter     stringFilter.list = list     return


You will want to change the 'arcpy.env.workspace' to your desired workspace.  You will also need to update 'arcpy.ListFeatureClasses' if you are working with another data type (i.e. rasters, tables).
0 Kudos
andrewtucker
New Contributor
Hi Andrew,

If you are using your script within a toolbox you can do this using the Tool Validation tab.  You would set a parameter (i.e. Input) under the Parameters tab of the script's Properties.  The Data Type for this parameter would be 'String'.  You can then update the initializeParameters function with the following:

def initializeParameters(self):
    arcpy.env.workspace = r"C:\temp\python\test.gdb"
    list = []
    lstFCs = arcpy.ListFeatureClasses("*")
    for fc in lstFCs:
       list.append(fc)
    stringFilter = self.params[0].filter
    stringFilter.list = list
    return


You will want to change the 'arcpy.env.workspace' to your desired workspace.  You will also need to update 'arcpy.ListFeatureClasses' if you are working with another data type (i.e. rasters, tables).


Thanks very much!

I'll give that a try now.

EDIT: Works like a charm!
0 Kudos