One way to get the latest file is as follows (which assumes you’re working in a Windows environment).
In a DS script, using the exec() function, run
"cmd /c dir *.csv > dircsv.txt
(I think that will work – can’t test for you right now) to send a list of the files names and their last modified dates and sizes into dircsv.txt, overwriting the file. Make a DS file format for it, and read it into a table. It’ll complain about the summary lines, if you actually setup the format to read the four separate columns; you can either 1) not care about that bit of slop, 2) get a 3rd party utility to generate your directory in a cleaner way (i.e., without summary lines), 3) configure your file format to read each line as one field and then parse the fields out in DS, later, or 4) something else. (Myself, I’d take, and have taken, choice #2.) Once you have the filenames and last modified dates in a table, the rest is easy: setup a WHILE loop, read the “latest” filename into a variable (you’ll need to decide if “latest” is determined by the file’s last modified attribute or that embedded date in the filename), use the variable as the filename of a file format that actually reads the CSV, etc.
Hope somebody has a more elegant solution, though, as this seems a lot of hoopla for a simple task.
Btw, when reading data from a file, you can include the filename as a column. So, in your case, yet another approach would just be to read all the data, from all the CSV files, at once, into a table, including the filename, and then figuring out “the latest” afterwards. (Maybe that’s the “more elegant solution”!)
JeffPrenevost
(BOB member since 2010-10-09)