开发者

Get detailed information on FileSystemEventArgs.ChangeType

开发者 https://www.devze.com 2022-12-27 01:25 出处:网络
I using the FileWatcher Class to locate changes on Files in a specific Folder. I m开发者_如何学JAVAanaged to detect Changes on Files but not detailed Information.

I using the FileWatcher Class to locate changes on Files in a specific Folder.

I m开发者_如何学JAVAanaged to detect Changes on Files but not detailed Information.

On the WatcherChangeTypes Enumeration Page

http://msdn.microsoft.com/en-us/library/t6xf43e0%28v=VS.100%29.aspx

they write the Change Type detects the changes include: changes to size, attributes, security settings, last write, and last access time.

Is there a way to detect which kind of change happened?

Thats the Event handler method i use.

private void OnChanged(object source, FileSystemEventArgs e)
{
     Console.WriteLine("File: " + e.FullPath + " Change Type: " + e.ChangeType);

}

Thank you in advance

Case


I think what you want is a FileSystemWatcher with a NotifyFilter tuned to a specific type of change(s):

var fsw = new FileSystemWatcher("C:\\");
fsw.NotifyFilter = NotifyFilters.LastAccess;
fsw.Changed += OnFileAccessed

private static void OnFileAccessed( object sender, FileSystemEventArgs e )
{
    ...
}

If you wanted different events to fire based on different change triggers, I believe you would need multiple watchers on the same file.

See FileSystemWatcher.NotifyFilter for more.

0

精彩评论

暂无评论...
验证码 换一张
取 消