I find the .Net FileSystemWatcher class really handy for writing utilities that automatically come to life when files show up in their watched folders. Is there any equivalent to this functionality in the *nix world that would allow me to watch a folder (and possibly all of its subdirectories)?
Edit: Preferably this will be something that doesn't require kernel patches.
That would be Gamin the File Alteration Monitor or Inotify.
Edit: Mono does have Gamin bindings - in fact, its implementation of FileSystemWatcher uses Gamin. See http://www.mono-project.com/FAQ:_Technical (search the page for FileSystemWatcher, the FAQ doesn't have anchors unfortunately.)
If you're using the wonderful QT library (www.qtsoftware.com) it's included as the QFileSystemWatcher.
Yes, dnotify and inotify.
I don't know if Mono has these wrapped, but it would be worth checking.
As has already being said, Mono has the class "System.IO.FileSystemWatcher", this is the relevant link: http://www.go-mono.com/docs/monodoc.ashx?link=T%3aSystem.IO.FileSystemWatcher
Greetings, I would like to share my observations using FileSystemWatcher in Mono in Ubuntu 10.10. Here is a very simple implementation of FileSystemWatcher in C#
This code was tested and works on both Windows XP and Ubuntu 10.10. However, I would like to point out that under Ubuntu 10.10 (possibly earlier versions as well), the FileSystemWatcher behaves uniquely.
If the directory that is being watched does not contain subdirectories, then invoking a FileSystemWatcher with the IncludeSubdirectories property set to true will result in the FileSystemWatcher ignoring events. However, if there are subdirectories in the target directory, then IncludeSubdirectories set to true will work as expected.
What will always work is if IncludeSubdirectories is set to false. In this instance, the FileSystemWatcher will only be watching the target directory.
I hope this is useful for programmers that would like to utilize Mono across different operating systems and invoke the FileSystemWatcher type.
chickenSandwich