文件监听

private void button1_Click_1(object sender, System.EventArgs e)
{
if(this.folderBrowserDialog1.ShowDialog()==DialogResult.OK)
{
if(this.folderBrowserDialog1.SelectedPath.Trim()!="")
{
this.textBox1.Text=this.folderBrowserDialog1.SelectedPath.Trim();
}
}
}

private void button2_Click(object sender, System.EventArgs e)
{
if(!System.IO.Directory.Exists(this.textBox1.Text))
{
MessageBox.Show("",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
this.fileSystemWatcher1.Path=this.textBox1.Text;
MessageBox.Show(this.textBox1.Text+"",MessageBoxButtons.OK,MessageBoxIcon.Information);

}

private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{//
this.richTextBox1.Text+=e.FullPath.ToString()+" ";
}

private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{//
this.richTextBox1.Text+=""+e.FullPath.ToString();
}

private void fileSystemWatcher1_Deleted(object sender, System.IO.FileSystemEventArgs e)
{//
this.richTextBox1.Text+=" "+e.FullPath.ToString();
}

private void fileSystemWatcher1_Renamed(object sender, System.IO.RenamedEventArgs e)
{//
this.richTextBox1.Text+=" "+e.FullPath.ToString();
}

原文地址:https://www.cnblogs.com/ouyangkai/p/10937981.html