FileSystemWatcher 的用法!

lfq_adam lfq_adam 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用textbox1找到要显示的文件,在listBox1中显示其所以的子目录!
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = folderBrowserDialog1.ShowDialog();
if (DialogResult.Cancel == dr)
return;
textBox1.Text = folderBrowserDialog1.SelectedPath;
FileSystemWatcher watch = new FileSystemWatcher(textBox1.Text);
watch.NotifyFilter = (NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName);
watch.Changed += new FileSystemEventHandler(OnChanged);//我每次运行到这里就直接过了,没有调用OnChanged
watch.EnableRaisingEvents = true;

}
private void OnChanged(object source, FileSystemEventArgs e)
{
WatcherChangeTypes changType = e.ChangeType;
string item = "";
item += DateTime.Now.ToString() + "---";
item += e.FullPath + ":";
item += changType.ToString();
listBox1.Items.Add(item);

}

这是什么原因呢?
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
lfq_adam
C# 111,129 成员 642,539 内容