Get files from a directory – C#/C Sharp

By | April 25, 2011

Hi,

Sometimes you may need to get the files from a specified directory using C# / C Sharp. See the sample code on how it works.

using System;
using System.IO;
 
class MainClass
{
  public static void Main()
  {
    string[] yourFiles = Directory.GetFiles("c:");
 
    foreach (string fNames in yourFiles)
 
      Console.WriteLine(fNames);
  }
 
}

This code will get you files from the root directory.

🙂

One thought on “Get files from a directory – C#/C Sharp

Leave a Reply

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