How does one extract each folder name from a path?

后端 未结 16 1596
傲寒
傲寒 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条回答
  •  清歌不尽
    2020-11-30 10:14

    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;
    

提交回复
热议问题