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 −
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# 中递归列出文件的详细内容。更多信息请关注PHP中文网其他相关文章!