I already managed to see file and folder changes with the FileSystemWatcher.
My problem is that I can't make a difference between files and folder. It's possible that a file and a folder have the same path names.
For the delete event I even can't use a dirty workarround with testing File.Exists(path) or Directory.Exists(path) because the file/folder is already deleted when the method is called.
Maybe this object has the info I need but I didn't found it:
FileSystemEventArgs e
I only want to know if the changed item was a file or a folder.
Assuming it's on a NTFS volume I think you could do what you need by looking at the Change Journals. Specifically the FSCTL_READ_USN_JOURNAL control code and looking at the FileAttributes of the USN_RECORD to see if it's a FILE_ATTRIBUTE_DIRECTORY.
You can find a sample here (in C++, but could possibly translate to C# or otherwise maybe just write a small C++ dll to call from your app): Walking a Buffer of Change Journal Records
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With