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

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

问题描述

我怎样才能(C:\Users\Ece\Documents\Testings)列表的文本文件在某一目录中一个WinForm(Windows应用程序)的列表框?

How can I list the text files in a certain directory (C:\Users\Ece\Documents\Testings) 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天全站免登陆