How To Ideas | How To Articles | How To Tutorials


0

How To Get List Of All The Files Present In A Folder Using C#


You are looking for a simple code that can give you list of all the files present in a folder or directory using C#, then this article is for you. In this article I will show you how can you get list of all the files present in a specific directory. I will just print the names of all the files in the Console, but you can perform some other operations as well.

Initialize DirectoryInfo instance

Declare and initialize a DirectoryInfo class instance which will hold the path to the directory you want to search for files.

DirectoryInfo dr = new DirectoryInfo(@"D:\");

Loop Through All The Files Of This Directory

Now loop through all the files this directory have, and perform any kind of operation you want to perform on any of these files.

foreach (var temp in dr.GetFiles())
{
      Console.WriteLine(temp.Name);
}

This will print the name of all the files that are present in the directory whose path you have given in the DirectoryInfo class object.

List Of Files In A Folder

Filed in: C# Tags: , , , , , , , , , , , ,

Leave a Reply

Submit Comment



© 0630 How To Ideas. All rights reserved.
Proudly designed by Theme Junkie.