FileSystemWatcher - Changed Event for ReadOnly Attribute

785 views Asked by At

It looks like the FileSystemMonitor is not firing a 'Changed' event (and no other events) when the ReadOnly attribute of a file in the monitored directory is changed.

This is my test code:

    using System;
    using System.IO;

    namespace FSM
    {
        class Program
        {
            static FileSystemWatcher FolderMonitor;


            static void Main(string[] args)
            {
            FolderMonitor = new FileSystemWatcher("C:\\MyImages");
            FolderMonitor.IncludeSubdirectories = false;
            FolderMonitor.Changed += FolderMonitor_Changed; ;
            FolderMonitor.EnableRaisingEvents = true;

            Console.WriteLine("Hit any key to terminate .....");
            Console.ReadKey(true);
        }


        private static void FolderMonitor_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("****  \"" + e.Name + "\" changed.");
        }
    }

With that code, I am receiving a lot of 'Changed' events, e.g. if the modification timestamp has changed, but not if I am changing any standard attributes like ReadOnly or Hidden.

Am I missing something, or have I hit a "feature"?

1

There are 1 answers

1
sclarke81 On BEST ANSWER

You need to set the NotifyFilter property as this determines the type of changes that are watched for. See FileSystemWatcher.NotifyFilter Property

e.g.

FolderMonitor.NotifyFilter = NotifyFilters.Attributes;