
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- Recursively List All Files in a Directory Including Symlinks
- Java program to List all files in a directory recursively
- Java program to delete all the files in a directory recursively (only files)
- How to rename multiple files recursively using Python?
- How to touch all the files recursively using Python?
- How to use Glob() function to find files recursively in Python?
- Recursively list nested object keys JavaScript
- How to Recursively Search all Files for Strings on a Linux
- Find middle of singly linked list Recursively in C++
- List files stored in SD Card connected to Arduino
- Recursively print all sentences that can be formed from list of word lists in C++
- Create directories recursively in Java
- How to list all files in a directory using Java?
- How to list the hidden files in a directory in Java?
- How do I list all files of a directory in Python?

Advertisements