How does one extract each folder name from a path?

后端 未结 16 1605
傲寒
傲寒 2020-11-30 09:18

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

16条回答
  •  猫巷女王i
    2020-11-30 10:22

    public static IEnumerable Split(this DirectoryInfo path)
    {
        if (path == null) 
            throw new ArgumentNullException("path");
        if (path.Parent != null)
            foreach(var d in Split(path.Parent))
                yield return d;
        yield return path.Name;
    }
    

提交回复
热议问题