FileSystemWatcher类-简单问题

| 我目前正在玩FileSystemWatcher类,想知道如何指定目录路径,但是它的所有子文件都是文件夹。因此它将查找C:\\中任何位置的任何更改,例如C:\\ Program Files \\ test等
string DirPath = \"C:\\\\*.*\";
我尝试添加。到Directroy的道路,但没有运气 源代码如下:
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();
}
    
已邀请:
使用FileSystemWatcher的IncludeSubdirectories属性。 如果添加行
FileWatcher.IncludeSubdirectories = true;
它将监视指定路径中的所有子目录。     
在所有C:上放置文件更改通知是一个糟糕的主意-如果您确实要监视整个卷,则可能应该使用《 USN Journal》     

要回复问题请先登录注册