私はブラウジングしましたが、私が探しているものに関する情報を見つけることができません.これをすでに超えている別の投稿がある場合は、お詫び申し上げます.
特定のフォルダーが別の人によって開かれたとき、またはそのフォルダーの下のファイルが開かれたときに、特定のフォルダーを監視するコードについて助けを求めています。この時点で、ユーザーがファイルを開いて変更したことを確認できますが、ファイルを開いて表示しただけでは、LastAccessed を追加してもイベントはスローされません。情報やヘルプをいただければ幸いです。
フォルダ名は C:\Junk
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);
}