C# 列出目录所有文件及子目录所有文件

public void FindFile(string dir) //参数为指定的目录
{

//在指定目录及子目录下查找文件,在listBox1中列出子目录及文件

DirectoryInfo Dir
= new DirectoryInfo(dir);

try
{
foreach (DirectoryInfo d in Dir.GetDirectories()) //查找子目录
{

FindFile(Dir
+ d.ToString() + "\\");

}
listView1.BeginUpdate();

foreach (FileInfo f in Dir.GetFiles("*.*")) //查找文件
{


listView1.Items.Add(Dir
+ f.ToString()); //listBox1中填加文件名

listView1.Items[j].SubItems.Add(f.Length.ToString());

j
= j + 1;


}

listView1.EndUpdate();
}
catch
{
MessageBox.Show(
"错误");
}

}

 

需要自己添加listView1控件

posted @ 2010-05-08 16:50  wangbin5542  阅读(1833)  评论(0编辑  收藏  举报