如何获取文件夹子目录的名称 [英] How to get the name of a folder subdirectory

查看:87
本文介绍了如何获取文件夹子目录的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取文件夹子目录的名称.如果我有一个带有2个子目录的名为候选人的文件夹,如何获得这2个子目录的名称.

How do i get the name of a folder subdirectory. If i have a folder called candidates with 2 subdirectories how do i get the names of those 2 subdirectories.

推荐答案

尝试下面的代码.指定文件夹"candidates"到"direcoryPath"变量的路径.

Try below code. Specify path of your folder "candidates" to "direcoryPath" variable.

string direcoryPath = @"c:\candidates";

string[] subDirectories= System.IO.Directory.GetDirectories(direcoryPath);


这应该做:

This should do:

class Program
{
    static void Main(string[] args)
    {
        DirectoryInfo directory = new DirectoryInfo(@"C:\MyDir");
        DirectoryInfo[] directories = directory.GetDirectories();

        foreach (DirectoryInfo dir in directories)
        {
            Console.WriteLine(dir.Name);
        }
    }
}



注意异常处理.

欢呼



Take care of exception handling.

Cheers


非常简单,在程序中使用System.IO,然后检查以下链接以探索与目录和子目录相关的类.我有一个样品,该样品当前不存在.无论如何,请检查以下链接和后续的示例程序将解决您的问题.快乐编码

http://msdn.microsoft.com/en-us/library/system.io.aspx [^ ]
Boss its very easy, use System.IO in in your program and then check the following link to explore Directory and Subdirectory related classes. I had a sample which is not there with me right the moment. Anyway checking the following link and subsequent sample programs will resolve your issue. Happy Coding

http://msdn.microsoft.com/en-us/library/system.io.aspx[^]


这篇关于如何获取文件夹子目录的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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