如何从路径中提取每个文件夹名称? [英] How does one extract each folder name from a path?

查看:119
本文介绍了如何从路径中提取每个文件夹名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路径是 \\server\folderName1\另一个名称\某事\另一个文件夹\

如果我不知道路径中有多少个文件夹并且不知道文件夹名称,如何将每个文件夹名称提取为字符串?

How do I extract each folder name into a string if I don't know how many folders there are in the path and I don't know the folder names?

非常感谢

推荐答案

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

编辑:
这将返回目录数组中的每个文件夹。您可以像这样获得返回的文件夹数:

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

int folderCount = directories.Length;

这篇关于如何从路径中提取每个文件夹名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆