Select to view content in your preferred language

Calling a file generated by a model which has a timestamp file name in Python

896
1
11-01-2011 04:39 PM
MelissaTalley
Emerging Contributor
I have a model which generates an output file with a timestamp attached to its name. This is necessary so that multiple users of our geoprocessing service do not overwrite eachother's outputs.

Within my model I have a python script which performs matrix algebra on a column of values calculated within the model. The values are loaded into the python script from a txt file generated by the model with the timestamp in the file name using the numpy command loadtxt.

My problem is that I cannot figure out how to tell the script what file to look for since the file is named differently every time.

The file name is generated in my model using calculate value which uses python to import the current time, this variable is named date in my model. The textfile is named %date%value.txt 
Is there a way to reference the result of calculate value in the model in my python script? If not is there another way to load a txt file that is named a little differently every time such as a wildcard in front of value.txt?
Tags (2)
0 Kudos
1 Reply
MathewCoyle
Honored Contributor
It depends on the formatting of your filename. Let's assume it has a name such as textfile = "april25_value.txt" If it is always the same length of "value" you can use something like this.
if textfile[-9:] == "value.txt"

or if it has a separator like an underscore, you can do
if textfile.rsplit("_")[1] == "value.txt"

There are other options as well, all depends on how the file names vary you want to process.
0 Kudos