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( " 错误 " );
}
}
{
// 在指定目录及子目录下查找文件,在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控件