Read Files List From Directory in C#

In this article, learn how to Read Files List From Directory in C# using System.IO library.


Read Files List From Directory in C#:

In the below example, you can see a c# program that prints a list of all files from a D:\Songs directory.

.
using System;  
using System.IO;  
  
namespace GetFilesFromDirectory  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            DirectoryInfo d = new DirectoryInfo(@"D:\Songs");    
            FileInfo[] Files = d.GetFiles();  
            Console.WriteLine("List of files available in this directory are.");  
            Console.WriteLine("************************************************");  
            foreach (FileInfo file in Files)  
            {                  
                Console.WriteLine("FileName : {0}" , file.Name);  
            }  
            Console.WriteLine("************************************************"); 
            Console.ReadLine();  
        }  
    }  
}  


– Article ends here –

If you have any questions, please feel free to share your questions or comments on the comment box below.

Share this:
We will be happy to hear your thoughts

      Leave a reply

      www.troubleshootyourself.com
      Logo