Hi, is there any way we can bring in an input file based on today's date? For example, if we save a file from a database every day, and today's file is called "20121114_Switch_Data.xlsx" can we have a default input (reader) to prepend today's date and grab the latest file?
Page 1 / 1
Yes, I would use a scripted parameter.
1) In the Workbench Navigator window, right-click User Parameters and choose Add Parameter.
2) Make the parameter type Scripted (either Tcl or Python, whichever you prefer) and in there create the name of the file to load by concatenating the constant parts with the current date (I assume there is a function in Tcl/Python to return the current date).
3) In the Navigator, find the Source parameter for your reader. Right-click and choose Unlink from User Parameter
4) Now right-click again and choose Link to User Parameter. Select the scripted parameter you just created.
I hope this helps. You'll need to do a very small amount of Tcl/Python coding, but it should be fairly simple.
And if you need some more hints, search for the term "scripted parameter" in the FMEpedia knowledgebase and you'll find some similar examples.
Regards
Mark
Following on from Mark,
Here is some Python (bit ugly) that you need to add to a Python User Parameter which will do the job for you.....
import datetime
datedetails = datetime.date.today().isoformat()
filename = datedetails.replace("-", "") + "_Switch_Data.xlsx"
return filename
I guess you could use featureReader http://evangelism.safe.com/fmeevangelist78/
You could create a single feature that holds todays date in attribute. Feed that feature as "initiator" into featureReader.
I would be surprised if there wasn't some "todays date" function somewhere, at the very least I would be extremely surprised if TCL doesn't have it. I would then look at attributeCreator + a little string processing to get the properly formatted date string.
If you'd prefer to avoid scripting and Python then an alternative approach is to use the Directory and File Pathnames reader to read the file names in the directory, process those with Sorter or StringSearcher and then once you've identifyed the file use FeatureReader as Hektopascal suggests.
Directory and File Pathnames returns all sorts of interesting information about the contents of directories but you'd probably use: path_windows - the full file name and path
path_rootname - the root name of the file, i.e. 20121021_Roads that you can use for sorting or string searching