I am using the Find Files Action to search a directory for .exe files.
The result gets written to a variable, from which i then try to extract only the first line (e.g. the first .exe that was found in the directory).
I have seen a couple examples in this forum, but none seemed to help.
The Regex i use is:
^(.*)$
and i tested it with a regex test tool on the web, there it matches the first line. So i guess i use the Text Find/Replace somehow wrong, it always places all 5 lines to the output variable.
The following Options are used:
Tab “Find String”
- Search in variable contents: Variable = Filename
- Searcg String as above
- Match as regular expression
- Match instances: First Only (Tried “All” Too, no change)
Tab “Replace”
- Replace text and write back to variable
- Replacement String: $1
- Expand variable names in replacement string
- Substitute regular expression matches (syntax is $&, …)
Thanks for your help.
Holger
Hi Holger
The Text Find/Replace action won’t be able to achieve what you want, and I couldn’t find any other actions that might do it (will have to think about how to implement this as an action).
The simplest option I found for this was a couple of lines of Javascript in the AfterAction script event of the Find Files action :
var files = FBVariables.FILES_FOUND.split(’\r\n’);if (files.length > 0 ) {FBVariables.FIRST_FILE = files[0];}
Note, adjust variable names to suite your project.