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())
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.