Question: I have a string that contains an exe full path and exe name like so:

```
mainExePath = "c:\Folder1\Folder2\MyProgram.exe"

```

I want to get jus the path like so:

```
"c:\Folder1\Folder2\"

```

I have tried this: 

```
string mainPath = System.IO.Path.GetFullPath(mainExePath);

```

but this returned the same string.

How can I do this?

Answer: 
Use `Path.GetDirectoryName(mainExePath)`
That would be

```
string mainPath = Path.GetDirectoryName(mainExePath);

```

This works for both paths including file names and paths only.

See the [documentation here](http://msdn.microsoft.com/en-us/library/system.io.path.getdirectoryname%28v=vs.110%29.aspx).