如何检测给定主文件夹下的所有子文件夹?
假设我的路径是 "c:/myapp/mainfolder/"
主文件夹中包含三个文件夹。 顺便说一句,它不需要识别主文件夹下的单独文件。
c:/myapp/mainfolder/subfolder1/
c:/myapp/mainfolder/subfolder2/
c:/myapp/mainfolder/subfolder3/
如何输入c:/myapp/mainfoder/
并获取输出:string[] subArrFolders = {subfolder1, subfolder2, subfolder3}
C#2.0 使用。
谢谢。
Assume my path is "c:/myapp/mainfolder/"
there are three folder included in the main folder.
BTW, It doesn't need to identify separate files under mainfolder.
c:/myapp/mainfolder/subfolder1/
c:/myapp/mainfolder/subfolder2/
c:/myapp/mainfolder/subfolder3/
How can I input c:/myapp/mainfoder/
and get the output: string[] subArrFolders = {subfolder1, subfolder2, subfolder3}
C#2.0 using.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Directory.GetDireatories() 获取 的子目录一条已知的路径。你可以这样使用它:
You can use Directory.GetDireatories() to get the sub directories of a known path. You can use it like this:
由于缺乏更好的信息,这个答案假设他要求子文件夹名称,而不是完整路径名称,这将给您:
这将允许您提取叶文件夹名称:
输出:
这里的关键区别是 DirectoryInfo类允许您通过 Name 属性获取叶目录名称。
For lack of better information this answer assumes he asked for the sub-folder name, not the full path name, which is what that will give you:
This will allow you extract the leaf folder name:
Output:
The key difference here is the DirectoryInfo class allows you to get the leaf directory name via the Name property.