Here we use Output Monitors to solve the problem of finding the most recent file in a directory. In this example, we want to find the most recently changed file in the c:\builds\source directory. This DOS command lists the files in order from oldest to newest: "dir /b /od /a-d c:\builds\source\*.* ".
The output is as follows:
Thus, we use an Output Monitor to retrieve the last line of the output.
1. Create a variable
First, create a variable to hold the name of the most recent file. Call it "filename".
2. Create a Run DOS Command / Batch File action
3. On the Runtime tab, click the Output Monitors ellipsis button (...)
Click "Add a New Output Monitor" then set the options as shown:
The Search String defines what lines of text are selected. In this case, we don't care what the text is - we just want the last one. So the *, combined with Use Wildcards matches any text.
The Behaviour lets you choose options like failing if the text doesn't match. The Save Last Match to Variable option is obviously the appropriate one here.
4. Choose the Variable you created - Filename.
The final result looks like this: