如何在列表框中列出选定目录中的文本文件? [英] How to list text files in the selected directory in a listbox?

查看:13
本文介绍了如何在列表框中列出选定目录中的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 WinForm(Windows 应用程序)的列表框中列出某个目录 (C:UsersEceDocumentsTestings) 中的文本文件?

How can I list the text files in a certain directory (C:UsersEceDocumentsTestings) in a listbox of a WinForm(Windows application)?

推荐答案

//文件在哪个目录?...

// 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);
}


//一个声明,然后是一个笑脸...那应该这样做.;o)


// A statement, followed by a smiley face... That oughta do it. ;o)

这篇关于如何在列表框中列出选定目录中的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆