# Extract filename from path

**URL:** https://www.finalbuilder.com/forums/t/extract-filename-from-path/2030
**Category:** Discussion
**Created:** [September 18, 2012, 4:26am UTC](https://www.finalbuilder.com/forums/t/extract-filename-from-path/2030 "2012-09-18T04:26:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [September 18, 2012, 4:26am UTC](https://www.finalbuilder.com/forums/t/extract-filename-from-path/2030/1 "2012-09-18T04:26:45Z")

</div>

I am trying to extract a filename from a path using Text Replace.

For example the input string can be any of the following:

**C:\Test2\Test.Project\Project1\Config\LastFile.txt**

**C:\LastFile.txt**

**C:\Local copy\spork\config items old\LastFile.txt**

&nbsp;

I am trying to use the regex option without any luck.&nbsp; The search string I am using is [^\\]$

Then trying to replace using $1

Any suggestions?

&nbsp;

thanks!

&nbsp;

&nbsp;

&nbsp;

&nbsp;

---

<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: [September 19, 2012, 12:23pm UTC](https://www.finalbuilder.com/forums/t/extract-filename-from-path/2030/2 "2012-09-19T12:23:45Z")

</div>

Hi Mike   
  
 The easiest way is to use the Set Variable action and the “Extract Filename portion from a path/filename” modifier.
