在 C# 中递归列出文件

在 C# 中递归列出文件

To get the list of files in a directory, use the SearchOptions.AllDirectories in C#.

Firstly, set the directory for which you want the files −

string[] myFiles = Directory.GetFiles("D:\New\", "*.*", SearchOption.AllDirectories);

The following is an example displaying files from the above mentioned directory −

Example

using System;
using System.Linq;
using System.IO;
class Program {
   static void Main() {
      string[] myFiles = Directory.GetFiles("D:\New\", "*.*", SearchOption.AllDirectories);
      foreach (string res in myFiles) {
         Console.WriteLine(res);
      }
   }
}

输出

以下是输出结果。它列出了文件夹的所有目录。

D:\New\one.txt
D:\New\two.html
D:\Newature.png

以上就是在 C# 中递归列出文件的详细内容,更多请关注编程之家其它相关文章!

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...