Home > Article > Backend Development > List files recursively in 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 −
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); } } }
The following is the output result. It lists all directories of a folder.
D:\New\one.txt D:\New\two.html D:\Newature.png
The above is the detailed content of List files recursively in C#. For more information, please follow other related articles on the PHP Chinese website!