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


C# DirectoryInfo.GetLength方法代码示例

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


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

示例1: DisplayDirectoryInfo

    // Retrieve all directories and files and display information about them.
    static void DisplayDirectoryInfo(DirectoryInfo[] directories, 
        DirectoryInfo rootDirectory, int levelInt)
    {
        FileInfo[] files;

        for (int i = 1; i <= levelInt; i++)
        {
            Console.Write("   ");
        }

        // TODO: Load the pre-declared "files" collection with references to all
        //      files directly in the current directory ("rootDirectory").
        files = rootDirectory.GetFiles();

        // TODO: Complete the WriteLine method below to specify the following
        //      info about the current directory ("rootDirectory"):
        //          0.  Its name.
        //          1.  Number of files.
        //          2.  Number of sub directories.
        Console.WriteLine("{0}: Files = {1}; Sub Directories = {2}",
            rootDirectory.Name,
            files.Length,
            rootDirectory.GetDirectories().Length);

        ++levelInt;

        if (directories.GetLength(0) > 0)
        {
            foreach (DirectoryInfo di in directories)
            {
                // TODO: Complete this method by calling it recursively
                //      for each directory ("di") in the "directories" collection.
                DisplayDirectoryInfo(di.GetDirectories(), di, levelInt);
            }
        }

        // Loop through each file in the current directory to display its info.
        foreach (FileInfo file in files)
        {
            for (int i = 1; i <= levelInt; i++)
            {
                Console.Write("   ");
            }

            // TODO: Complete the WriteLine method below to specify 3
            //      properties about the "file":
            //          0.  Its name.
            //          1.  The last time it was written.
            //          2.  Its size.
            Console.WriteLine("{0}: {1}; {2} bytes",
                file.Name,
                file.LastWriteTime,
                file.Length);
        }
    }
开发者ID:Meowse,项目名称:student1,代码行数:56,代码来源:Program.cs


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