Question: I have a vb string with this value: `c:\program\bin\files`

I need to convert this string to this value: `files`

All i need is the last folder of the path.

The path is not fixed. It can be anything like: `d:\app\win\7\sp1\update`

In this case the string must be converted to: `update`

I think that should be done by searching the string backwards for the first occurrence of `\` and removing everything before it, including the `\` itself.

But obviously i don't know how to do it. :)

Thank you!

**EDIT:**

I need to use this to fill a ComboBox...

This is what i am using:

```
ComboBox1.Items.AddRange(IO.Directory.GetDirectories(appPath & "\Updates\Version"))

```

It gives me a ComboBox like:

```
c:/program/Updates/Version/Beta1
c:/program/Updates/Version/Beta2
c:/program/Updates/Version/Beta3
c:/program/Updates/Version/Beta4

```

And i would like to have the ComboBox like:

```
Beta1
Beta2
Beta3
Beta4

```

Answer: 
Rather than try to pull apart the string yourself, have a look at the [System.IO.Path](https://msdn.microsoft.com/en-us/library/system.io.path(v=vs.110).aspx) class. 

In your case, the GetFileName method does what you want:

```
  lastFolder = System.IO.Path.GetFileName(path)

```

To fill a combo box with names you can use a LINQ query like this:

```
ComboBox1.Items.AddRange(
  From path 
  In IO.Directory.GetDirectories(IO.Path.Combine(appPath, "Updates\Version"))
  Select IO.Path.GetFileName(path))

```

Also, try to use the Path.Combine method when joining path fragments together. It's safer than just joining strings.
In VBScript, which this is tagged you have two choices. This was written before any code was edited into the question.

Use `InstrR` which is `Instr` but from back to front of string.

You also have `StrReverse` which reverses a string.

> 
> **InStrRev**
> 
> 
> Returns the position of an occurrence of one string within another, from the end of string. 
> 
> 
> 
> ```
> InStrRev(string1, string2[, start[, compare]])
> 
> ```
> 
> **StrReverse**
> 
> 
> Returns a string in which the character order of a specified string is reversed.
> 
> 
> 
> ```
> StrReverse(string1)
> 
> ```
> 
> 

If using the File System Object it has a method to do specifically what you want.

> 
> **GetParentFolderName** **Method** 
> 
> 
> Returns a string containing the name of the parent folder of the last component in a specified path.
> 
> 
> 
> ```
> Set fso = CreateObject("Scripting.FileSystemObject")
> object.GetParentFolderName(path) 
> 
> ```
> 
>