- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to list down all the files available in a directory using C#?
Firstly, use the DirectoryInfo object −
//creating a DirectoryInfo object DirectoryInfo mydir = new DirectoryInfo(@"d:\amit");
Now, use the GetFiles() method to get all the files −
FileInfo [] f = mydir.GetFiles();
To get the list of files in a directory, try to run the following code −
Example
using System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { //creating a DirectoryInfo object DirectoryInfo mydir = new DirectoryInfo(@"d:\amit"); // getting the files in the directory, their names and size FileInfo [] f = mydir.GetFiles(); foreach (FileInfo file in f) { Console.WriteLine("File Name: {0} Size: {1}", file.Name, file.Length); } Console.ReadKey(); } } }
- Related Articles
- How to list all files in a directory using Java?
- How to list down all the files alphabetically using Python?
- How to list all files (only) from a directory using Java?
- C Program to list all files and sub-directories in a directory
- Java program to List all files in a directory recursively
- How can I get the list of files in a directory using C/C++?
- How do I list all files of a directory in Python?
- How to list down all the available commands and aliases on Linux?
- How can I get the list of files in a directory using C or C++?
- How to list out the hidden files in a Directory using Java program?
- How to read data from all files in a directory using Java?
- Java program to List all files in a directory and nested sub-directory - Recursive approach
- How to get all the files, sub files and their size inside a directory in C#?
- How to list the hidden files in a directory in Java?
- How to delete all files in a directory with Python?

Advertisements