- 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
EnumerateFiles method in C#
EnumerateFile() method is used in C# to get all the files. Use AllDirectories property to recurse through directories −
Directory.EnumerateFiles(@"D:\NEW", "*.*", SearchOption.AllDirectories)
To get the list of files in a directory, use the SearchOptions.AllDirectories in C# as shown above.
Let us see how −
Example
using System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { foreach (string allFiles is Directory.EnumerateFiles(@"D:\NEW","*.*",SearchOption.AllDirectories)) { Console.WriteLine(allFiles); } } } }
Output
The following is the output −
D:\NEW\my.txt D:\NEW\amit.html D:\NEW\tutorials\java\a.java
Advertisements