FileSystemWatcher usado para assistir a pasta / arquivo aberto
Eu tenho navegado por aí, mas não consigo encontrar qualquer informação sobre o que estou procurando, se houver outro post que já passa por isso, então peço desculpas.
Eu estou procurando ajuda com código que irá monitorar uma pasta específica para quando a pasta é aberta por outra pessoa ou quando um arquivo na pasta é aberto. Neste ponto eu posso ver quando um usuário abre e modifica os arquivos, mas se eles apenas abrem o arquivo para visualizá-lo, ele não lança um evento mesmo quando eu adiciono LastAccessed. Qualquer informação ou ajuda seria apreciada.
O nome da pasta é C: \ Junk
Código no C # 4.0:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\";
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = "junk";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}