- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
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); } } }
Output
The following is the output. It lists all the directories of the folder −
D:\New\one.txt D:\New\two.html D:\New
ature.png
Advertisements