How does one extract each folder name from a path?

string mypath = @"..\folder1\folder2\folder2";
string[] directories = mypath.Split(Path.DirectorySeparatorChar);

Edit:
This returns each individual folder in the directories array. You can get the number of folders returned like this:

int folderCount = directories.Length;

Leave a Comment