c# - How do I extract each folder name from a path? -


how extract each folder name path if don't know how many folders there in path , don't know folder names?

you can use string.split:

string filename = @"c:\foo\bar\baz.txt"; string directory = path.getdirectoryname(filename); // "c:\foo\bar" string alldirectorynames = directory.split('\\'); // ["c:", "foo", "bar"] 

Comments