private void button1_Click(object sender, EventArgs e)
{
SearchFile(textBox2.Text);
MessageBox.Show("search 結束");
}
public void SearchFile(string fileName)
{
DirectoryInfo dir = new DirectoryInfo(fileName);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
foreach (FileSystemInfo file in fileinfo)
{
if (file is DirectoryInfo)
SearchFile(file.FullName);
else
{
if (file.Name==textBox1.Text)
{
FileInfo fi = new FileInfo(file.FullName);
listView1.Items.Add(fi.Name);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(fi.FullName);
listView1.Items[listView1.Items.Count - 1].SubItems.Add(fi.Length.ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(fi.CreationTime.ToString());
}
}
}
查找文件,由於編寫設定為資料夾底下,所以只能找尋資料夾底下的內容