Home > DeveloperSection > Forums > How can I read all files in a directory to an array using C#?
Lady Bird Johnson
Lady Bird Johnson

Total Post:20

Posted on    October-05-2013 7:56 AM

 C# C# 

 1 Reply(s)
 1042  View(s)
Rate this:

I have a folder D:\MyDirectory that is full of tab-delimited text files, but the number of files is unknown at any given time. How Can  I read and store the names of the text files in the MyDirectory directory into an array?

Hank Greenberg
Hank Greenberg

Total Post:12

Posted on    October-05-2013 9:02 AM

You should use System.IO.Directory.GetFiles() and if know the file extension then you should use use System.IO.Directory.GetFiles(@"C:\ MyDirectory*.txt")

Don't want to miss updates? Please click the below button!

Follow MindStick