Looping through Filenames in the selected directory folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI,
I am new to C# and It might be a simple question.
I want to loop through filenames and ignore subfolder and its files. I have
to display all files names in the screen.

Please help me how to do it using C#.

thanks,
 
You'll need to add "using System.IO;"

DirectoryInfo di = new DirectoryInfo(@"c:\");
foreach (FileInfo fi in di.GetFiles())
{
Console.WriteLine(fi.Name);
}
Console.ReadLine();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top