Question: I'm pulling a file path from a database to use as a file source.
I need to remove the last folder from the source path, so I can then create new folders to use as the destination path.

Example source file path:
`\\\\ServerName\\Documents\\MasterDocumentFolder\\`

I need to remove the last folder from that string and get this:
`\\\\ServerName\\Documents\\`

So I can create a folder like this:
`\\\\ServerName\\Documents\\NewDocumentFolder1\\`

Edit: I have updated my example paths to show why the Path.GetDirectoryName() won't work in this case.

Answer: 
Thats ugly, but works

```
string path = @"C:\Documents\MasterDocumentFolder\file.any";
var lastFolder = Path.GetDirectoryName(path);
var pathWithoutLastFolder = Path.GetDirectoryName(lastFolder);

```

But if you have less than one level of directories (drive root), then `pathWithoutLastFolder` will be `null`, so you have to deal with it.
This should account for the path being either a file or directory

```
DirectoryInfo parent = null;
if (File.Exists(path))
{
    parent = new FileInfo(path).Directory.Directory
}
if(Directory.Exists(path))
{
    parent = new DirectoryInfo(path).Directory;
}

```