I am using a .NET FileSystemWatcher on a Windows server to watch a folder on a Windows server. I also have access to the same folder from a Linux server using Samba. If I copy a file from the watched folder to somewhere else, a change event is generated for the source file. Is this behaviour correct? It seems to change the 'last accessed' time on the file. How can I ignore this type of change?
+1
A:
The "last accessed" time is inconsistently set by Windows programs: for instance, displaying the file properties context menu in Windows will reset this time. As you state, Windows Copy does not set the "last access" time, but a copy of a file on a Windows server using Samba does as it's Samba's internal drivers doing the copy.
Your only workaround, I fear, is to ignore the "last access" time using a filter in your FileSystemWatcher:
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "c:\yourpathhere";
watcher.NotifyFilter = NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
or similar.
Jeremy McGee
2009-08-30 12:43:50