2

I know this question is somewhat subjective, but I think it might be a valid question to ask.

I want to create a program that watches folders on a file server. The program itself runs on the server, so network folders don't have to be monitored. I want to get an event in case a folder/file gets deleted, moved, created and such. These information will be written to the disk (where the network users can't access it). I would need the name of the file, and the user who caused it, and maybe more info, but that's the minimum requirement for now.

  1. In C# we can use the FileSystemWatcher-Class, which is very unreliable. (Examples for that can be found around StackOverflow a lot.)

  2. We also could use the Auditing Feature of Windows 7 Professional (which I am running on), but this also gives many, many confusing entries in the system log. I just can't get reliable information from those.

  3. Third, one could just poll the files and compare. This is kind of the brute force attack I would like to omit. Also, the other methods might be almost realtime, this one is not.

So, I could think of combining 1. and 3., and maybe even 2., too, but what is the clean, the good way to do this?

tshepang
  • 12,111
  • 21
  • 91
  • 136
HansM
  • 21
  • 1
  • 4
  • 1
    "FileSystemWatcher" isn't "very unreliable". The programmers who fail to use it properly (i.e. don't handle overflow properly), however, are. Use `FileSystemWatcher`. Anything else is silly. You just have to handle its limitations properly. – Matthew Watson Oct 07 '13 at 09:30
  • 1
    (To be more precise: If you do get a `FileSystemWatcher.Error` event, you need to check the type of error, then if it's an overflow check all the files to see what's new, which means maintaining a list against which to check the files) – Matthew Watson Oct 07 '13 at 09:36
  • @MatthewWatson Could you point me into the right direction? Do you mean some kind of polling if an error occurs? – HansM Oct 07 '13 at 09:38
  • See here for an example determining the error type: http://stackoverflow.com/questions/11667041/whats-the-best-practice-to-recover-from-a-filesystemwatcher-error and http://stackoverflow.com/questions/6184115/filesystemwatcher-stops-catching-events It doesn't tell you how to respond, but you could get a listing of all the files and do something with it. Chances are you'll never see this error - but you can test it by dragging and dropping a LARGE number of small files into the folder. – Matthew Watson Oct 07 '13 at 09:42
  • 1
    why not run it through a batch you can compare files in batch by 1 using the tree command with the find and if commands so like tree find # of files containing so.so string /c if file count gtr 123** goto *** what ever action you want it to do. 2 is to have it copy the folders to temp folder then use the compare command to see what has changed. – CMS_95 Oct 16 '13 at 01:03

0 Answers0