My path is \\\\server\\folderName1\\another name\\something\\another folder\\
How do I extract each folder name into a string if I don\'t know how many
I see your method Wolf5370 and raise you.
internal static List Split(this DirectoryInfo path)
{
if(path == null) throw new ArgumentNullException("path");
var ret = new List();
if (path.Parent != null) ret.AddRange(Split(path.Parent));
ret.Add(path);
return ret;
}
On the path c:\folder1\folder2\folder3 this returns
c:\
c:\folder1
c:\folder1\folder2
c:\folder1\folder2\folder3
In that order
internal static List Split(this DirectoryInfo path)
{
if(path == null) throw new ArgumentNullException("path");
var ret = new List();
if (path.Parent != null) ret.AddRange(Split(path.Parent));
ret.Add(path.Name);
return ret;
}
will return
c:\
folder1
folder2
folder3