日期:2014-05-17 浏览次数:20835 次
private void button2_Click(object sender, EventArgs e)
{
this.folderBrowserDialog1.Description = "请请选择监控路径";
if (this.folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text = this.folderBrowserDialog1.SelectedPath;
this.fileSystemWatcher1 = new System.IO.FileSystemWatcher();
this.fileSystemWatcher1.Path = this.textBox1.Text;
this.fileSystemWatcher1.IncludeSubdirectories = true;
this.fileSystemWatcher1.Created += new FileSystemEventHandler(watcher_Change);
this.fileSystemWatcher1.Deleted += new FileSystemEventHandler(watcher_Change);
this.fileSystemWatcher1.Renamed += new RenamedEventHandler(watcher_reName);
this.fileSystemWatcher1.EnableRaisingEvents = true;
}
}
private void watcher_Change(object sender, FileSystemEventArgs e)
{
MessageBox.Show(e.ChangeType + "\n" + e.FullPath);
}
private void watcher_reName(object sender, RenamedEventArgs e)
{
MessageBox.Show("Change File: \n" + e.OldName + "\n to: \n" + e.Name);
}