# Extracting Folder Name from a Path

**URL:** https://www.finalbuilder.com/forums/t/extracting-folder-name-from-a-path/1192
**Category:** Discussion
**Created:** [May 1, 2009, 5:20am UTC](https://www.finalbuilder.com/forums/t/extracting-folder-name-from-a-path/1192 "2009-05-01T05:20:35Z")
**Posts on this page:** 3
**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: [May 1, 2009, 5:20am UTC](https://www.finalbuilder.com/forums/t/extracting-folder-name-from-a-path/1192/1 "2009-05-01T05:20:35Z")

</div>

Hi, I have a variable in FinalBuilder that has the text of a full path and I want to extract the Top Level folder name from it.

Is there an easy way to do that ?

Example :

myVar contains : "C:\Test\myScripts\AnotherFolder\"

and I want to extract "AnotherFolder" into a new variable.

Thank you very much.

---

<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: [May 3, 2009, 11:48am UTC](https://www.finalbuilder.com/forums/t/extracting-folder-name-from-a-path/1192/2 "2009-05-03T11:48:58Z")

</div>

Hi

If the Name is in D, you can write a tiny script using the action : Run Script

D1 = Left(D, Len(D)-1)  
&nbsp; ' Chop last Char From D  
&nbsp; P =&nbsp; InStrRev(D1,"\")  
&nbsp; ' Find Last \ in D1  
&nbsp; L = Len(D1)  
&nbsp; D2 = mid(D1,P+1,L)

You will get the name in D2

Daphna Levin

&nbsp;

---

<div class="post-metadata">

### Author: ![djmarks](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@djmarks](https://www.finalbuilder.com/forums/u/djmarks)
#### Post date: [May 4, 2009, 7:50am UTC](https://www.finalbuilder.com/forums/t/extracting-folder-name-from-a-path/1192/3 "2009-05-04T07:50:05Z")

</div>

Is it the same structure for all your locations?   
  
 C:\Test\myScripts\AnotherFolder"   
 C:\Test\myScripts\AnotherFolder1"   
 C:\Test\myScripts\AnotherFolder2"   
  
 If so you an use the Path Action to extract the name as well as set the location through myscripts to be its own variable and strip that away as well.
