我目前正在玩FileSystemWatcher类,想知道如何指定目录路径,但它的所有子文件都是文件夹。因此,它将在C:\ \例如C:\Program \test等任何地方查找任何更改。
string DirPath = "C:\\*.*";我试着加了。直奔正道,但没有运气
源代码如下:
static void Main(string[] args)
{
string DirPath = "C:\\*.*";
FileSystemWatcher FileWatcher = new FileSystemWatcher(DirPath);
FileWatcher.Changed += new FileSystemEventHandler(FileWatcher_Changed);
FileWatcher.Created += new FileSystemEventHandler(FileWatcher_Created);
FileWatcher.Deleted += new FileSystemEventHandler(FileWatcher_Deleted);
FileWatcher.Renamed += new RenamedEventHandler(FileWatcher_Renamed);
FileWatcher.EnableRaisingEvents = true;
Console.ReadKey();
}发布于 2011-05-19 21:30:01
使用IncludeSubdirectories属性的FileSystemWatcher。
如果你加上这行
FileWatcher.IncludeSubdirectories = true;它将监视指定路径中的所有子目录。
发布于 2011-05-20 07:03:55
在所有C:上添加一个文件更改通知是个糟糕的主意--如果您真的想监视整个卷,那么您可能应该使用USN杂志
https://stackoverflow.com/questions/6065053
复制相似问题