How can I list the text files in a certain directory (C:\Users\Ece\Documents\Testings) in a listbox of a WinForm(Windows application)?
Right-click that folder and select Show more options. Click Copy File List to Clipboard on the classic menu. You'll still need to paste the copied list into a text file. Launch Run, type Notepad in the Open box, and click OK.
You can use dir /b > files. txt from the command-line to get the list of filenames stored into files. txt .
// What directory are the files in?...
DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestDirectory");
// What type of file do we want?...
FileInfo[] Files = dinfo.GetFiles("*.txt");
// Iterate through each file, displaying only the name inside the listbox...
foreach( FileInfo file in Files )
{
listbox1.Items.Add(file.Name);
}
// A statement, followed by a smiley face... That oughta do it. ;o)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With