Best way to find latest file having filename pattern?

I have several action lists that start by finding files with a certain pattern (like ‘FilePatternYYYYMMDD.csv’, where YYYYMMDD is the date when the file was created). I want to work with the latest file. I have been creating a fileset based on the pattern and sorting it by filename…but I am not sure of the most efficient way to get the first (or last, depending on sort) filename in the list. I just iterate through, and grab the first (or last) file in the iteration for the variable I want, but it seems like there should be an easier way to just grab the one filename I need.

Would using FileSet to Variable help at all? That would create a text list - could I easily get the first item in a variable list without an iterator? Or is there a way to “break out” of the iteration once I have the file I need?

Hi Jonathan

You can use the Exit Loop action to break out of the iterator loop.

So the idea would be to sort descending (to grab the latest file first), and as soon as I assign the variable the first time I use Exit Loop? I will try that, thanks.