0

Is there a way to see what exactly changed when OnChanged is called? I am trying to filter out file attribute changes.

Logick
  • 301
  • 1
  • 6
  • 14
  • In the event you weren't aware [FileSystemWatcher doesn't always behave](http://stackoverflow.com/questions/239988/filesystemwatcher-vs-polling-to-watch-for-file-changes). – Mike Oct 09 '13 at 18:54

3 Answers3

2

The method provides an argument of type FileSystemEventArgs, which supplies data on the type and path of the change.

You can use this to filter only the WatcherChangeTypes.Changed value, which is:

The change of a file or folder. The types of changes include: changes to size, attributes, security settings, last write, and last access time.

See @Oliver's answer for the supplemental info to this answer, I was just about to add that :)

Rotem
  • 21,452
  • 6
  • 62
  • 109
2

You can use NotifyFilter property to specify what kind of change you want to observe. As Rotem already stated the FileSystemEventArgs class also provides some information of a change.

Oliver
  • 1,507
  • 1
  • 12
  • 23
0

I don't think you can filter out anything as granular as which attributes were changed. You can use the NotifyFilters property to specify that you only want to raise events when file attributes were changed. The event is raised when each change happens so you can in response to the event simply create a FileInfo class with the provided path of the file and inspect the new attributes.

Trevor Elliott
  • 11,292
  • 11
  • 63
  • 102