Question: I have a filepath say "C:\hello\hi\dotnet\abc.txt". I just want the directories from the path.

Expected Output :

```
hello
hi
dotnet

```

I have used `Path.DirectorySeparatorChar` but it doesn't work.So help me out to solve this problem.

Answer: 
How about: -

```
string filename = @"C:\hello\hi\dotnet\abc.txt";
string dirName = Path.GetDirectoryName(filename);   // C:\hello\hi\dotnet
string pathRoot = Path.GetPathRoot(dirName);        // C:\
string result = dirName.Substring(pathRoot.Length); // hello\hi\dotnet

```
You Can Do 

```
string filePath="C:\\DocumentsAndSettings\\Users\\Xyz\\Downloads\\abc.txt";
filePath=Path.GetFullPath(filePath);
var split =filePath.Split('\\');
var sp = split.Take(split.Length - 1);
foreach ( var st in sp)
{
     Console.WriteLine(st);
}

```