监控文件或目录的变化的代码

下面的代码段是关于监控文件或目录的变化的代码,应该能对码农有用。

public void StartMonitor(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = path;

watcher.NotifyFilter = NotifyFilters.FileName;
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}

private void OnChanged(object source, FileSystemEventArgs e)
{
string word = DocumentUtility.ConvertPdfToDoc(e.FullPath);
}




 

posted @ 2021-12-04 13:14  androidyou  阅读(73)  评论(0编辑  收藏  举报