[C#] How to Get Files in a Directory in C#

Byantonhyip

Mar 12, 2019 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Chia sẻ

Hello friends !

Now, we will learn How to Get Files in a Directory in C#.  

The GetFiles method gets a list of files in the specified directory. To get file names from the specified directory, use static method Directory.Get­Files. Lets have these files and subfolders in “C:Temp” folder.

This example shows how to get list of file names from a directory (including subdirectories). You can filter the list by specific extension.

string root = @"C:Temp";
string[] fileEntries = Directory.GetFiles(root);
foreach (string fileName in fileEntries) 
{
    Console.WriteLine(fileName);
}

I wish you success, please leave a comment below, we will answer all your questions.

GoodLuck !!!

 

 

 


Chia sẻ
Xem thêm  [C#] How to create a Directory in C#

Leave a Reply

Your email address will not be published. Required fields are marked *