想做一个简单像杀毒软件那样的文件扫描功能,请问怎么实现??
想做一个简单的文件扫描功能,也就是像杀毒软件扫描本地硬盘一样,扫到的文件不断的显示出来,请问高手这个要怎么去实现呢?? 我试着用以下程序去实现,但运行时都会卡住几秒,最后只能显示到扫描到的最后一个文件名,郁闷~~~
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace CPic
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSearch_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你确定要修改吗?", "消息框", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
String myPath = txtPath.Text;
if (myPath == "" ¦ ¦ myPath == null)
{
lblMsg.Text = "请输入地址!";
//MessageBox.Show("请输入地址!");
txtPath.Focus();
}else {
FindAllFile(myPath);
}
}
}
public void FindAllFile(string path)
{
DirectoryInfo[] ChildDirectory;//子目录集
FileInfo[] NewFileInfo;//当前所有文件
DirectoryInfo FatherDirectory = new DirectoryInfo(path); //当前目录
ChildDirectory = FatherDirectory.GetDirectories("*.*"); //得到子目录集
NewFileInfo = FatherDirectory.GetFiles();//得到文件集,可以进行操作
// lblMsg.Text = lblMsg.Text + "\n+" + FatherDirectory.Name + "/";
foreach (FileInfo fi in NewFileInfo)
{
//lblMsg.Text = lblMsg.Text + "\n" + fi.Name;
lblMsg.Text = fi.Name;
}
foreach (DirectoryInfo dirInfo in ChildDirectory)
{
FindAllFile(dirInfo.FullName);
}
}
}
}