Hi Tony!
I just wonder when you use the Attributes on NotifyFilter what kind of
changes is that you catch then.
It's easy to understand what you are monitoring when you use the
NotifyFilter in this way NotifyFilter.Size
but when you use NotifyFilter in this way
myFileSystemWatcher.NotifyFilter = NotifyFilter.Attributes;
it's more difficult to know what you are monitoring.
Can you give some examples ?
NotifyFilters.Attributes filters for any Attribute changes.
An example Program that you can simply use to test it yourself (Simply a
Console Application - replace the content of program.cs):
using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
public static void Main(string[] args)
{
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"c:\temp";
watcher.NotifyFilter = NotifyFilters.Attributes;
// Only watch text files.
watcher.Filter = "*.txt";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
// Begin watching.
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);
}
}
}
Then you can simply play around - create a new file and change the
attributes with attrib command.
Or did you mean a possible example? Maybe you want to use the archive
flag to find files that should be immediately be backed up. So you need
a watcher that looks for attribute changes, check if the archive bit is
set to just start the backup (and removal of the flag afterwards). Or
you want to be sure, that some files are always compressed or not
compressed or whatever .... you can imagine of everything.
What I saw in my tests: This example also showed changes to the content
of the file. That wasn't expected from my side and it wasn't your
question so far. I didn't try to investigate this much fuch further so
far.
With kind regards,
Konrad