Search code examples
c#filesystemwatcher

How to filter system files in C#


I am using FileSystemWatcher for tracking file system for any changes. But my customer does not want any system file change records. He just wants "changed by user" records. How can I do this?


Solution

  • Subscribe for the FileSystemWatcher.Changed event and filter the files manually:

    MyFolderWatcher.Changed += (s, e) => {
        if ((File.GetAttributes(e.FullPath) & FileAttributes.System) != FileAttributes.System)
            ; // Do something
    }