当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.GetDirectories方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.GetDirectories方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetDirectories方法的具体用法?C# DirectoryInfo.GetDirectories怎么用?C# DirectoryInfo.GetDirectories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.GetDirectories方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.IO;

public class GetDirectoriesTest 
{
    public static void Main() 
    {

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("c:\\");

        // Get a reference to each directory in that directory.
        DirectoryInfo[] diArr = di.GetDirectories();

        // Display the names of the directories.
        foreach (DirectoryInfo dri in diArr)
            Console.WriteLine(dri.Name);
    }
}
开发者ID:.NET开发者,项目名称:System.IO,代码行数:20,代码来源:DirectoryInfo.GetDirectories

示例2: Main

//引入命名空间
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            DirectoryInfo di = new DirectoryInfo(@"c:\");

            // Get only subdirectories that contain the letter "p."
            DirectoryInfo[] dirs = di.GetDirectories("*p*");
            Console.WriteLine("The number of directories containing the letter p is {0}.", dirs.Length);

            foreach (DirectoryInfo diNext in dirs) 
            {
                Console.WriteLine("The number of files in {0} is {1}", diNext, 
                    diNext.GetFiles().Length);
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
开发者ID:.NET开发者,项目名称:System.IO,代码行数:28,代码来源:DirectoryInfo.GetDirectories

示例3: Main

//引入命名空间
using System;
using System.IO;

class App
{
    public static void Main()
    {
        // Specify the directory you want to manipulate.
        string path = @"c:\";
        string searchPattern = "c*";

        DirectoryInfo di = new DirectoryInfo(path);
        DirectoryInfo[] directories = 
            di.GetDirectories(searchPattern, SearchOption.TopDirectoryOnly);

        FileInfo[] files = 
            di.GetFiles(searchPattern, SearchOption.TopDirectoryOnly);

        Console.WriteLine(
            "Directories that begin with the letter \"c\" in {0}", path);
        foreach (DirectoryInfo dir in directories)
        {
            Console.WriteLine(
                "{0,-25} {1,25}", dir.FullName, dir.LastWriteTime);
        }

        Console.WriteLine();
        Console.WriteLine(
            "Files that begin with the letter \"c\" in {0}", path);
        foreach (FileInfo file in files)
        {
            Console.WriteLine(
                "{0,-25} {1,25}", file.Name, file.LastWriteTime);
        }
    } // Main()
} // App()
开发者ID:.NET开发者,项目名称:System.IO,代码行数:37,代码来源:DirectoryInfo.GetDirectories

示例4: DirectoryInfo.GetDirectories()

//引入命名空间
using System;
using System.IO;
public class DirectoryCounter {
    public static void Main() {
        DirectoryInfo myDir = new DirectoryInfo(@"c:\Program Files");
        int total = CountDirectories(myDir);
        Console.WriteLine(total);
    }

    public static int CountDirectories(DirectoryInfo dir) {
        DirectoryInfo[] dirs = dir.GetDirectories();
        int count = dirs.Length;
        foreach (DirectoryInfo subDir in dirs) {
            count += CountDirectories(subDir);
        }
        return count;
    }
}
开发者ID:C#程序员,项目名称:System.IO,代码行数:19,代码来源:DirectoryInfo.GetDirectories


注:本文中的System.IO.DirectoryInfo.GetDirectories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。