# Extract first Item from Find File(s) Action

**URL:** https://www.finalbuilder.com/forums/t/extract-first-item-from-find-file-s-action/2584
**Category:** Discussion
**Created:** [December 19, 2017, 8:33am UTC](https://www.finalbuilder.com/forums/t/extract-first-item-from-find-file-s-action/2584 "2017-12-19T08:33:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![holger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@holger](https://www.finalbuilder.com/forums/u/holger)
#### Post date: [December 19, 2017, 8:33am UTC](https://www.finalbuilder.com/forums/t/extract-first-item-from-find-file-s-action/2584/1 "2017-12-19T08:33:24Z")

</div>

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).  
  
&nbsp;I have seen a couple examples in this forum, but none seemed&nbsp; to help.   
  
The Regex i use is:  
  
&nbsp;^(.\*)$   
  
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

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [December 19, 2017, 10:39am UTC](https://www.finalbuilder.com/forums/t/extract-first-item-from-find-file-s-action/2584/2 "2017-12-19T10:39:23Z")

</div>

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.
