本帖最后由 shorlyn 于 2014-9-3 09:34 编辑
[C#] 纯文本查看 复制代码 string path = @"D:\BiZhi";
string fileType = "*.jpg";
public Form1()
{
InitializeComponent();
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = path;
fsw.Filter = fileType;
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
fsw.Created+=new FileSystemEventHandler(fsw_Created);
fsw.Deleted += new FileSystemEventHandler(fsw_Deleted);
fsw.EnableRaisingEvents = true;
}
private void fsw_Deleted(object sender, FileSystemEventArgs e)
{
this.FileChanged();
}
private void fsw_Created(object sender, FileSystemEventArgs e)
{
this.FileChanged();
}
private void fsw_Changed(object sender, FileSystemEventArgs e)
{
this.FileChanged();
}
private void FileChanged()
{
string[] str = Directory.GetFiles(path, fileType);
MessageBox.Show(str.Length.ToString());
}
|