FileSystemWatcher - has any one done this?

I’d like to monitor a folder and when someone drops a file in there I
can take the files name and add it to a database.

My dream is to have a folder always being watched. and if someone
drops a file or folders with files into that watched folder, I take
the filename(s) and insert them into a db and if the files are in
folder I use the folder name(s) as tags for that file.

make sense? can it be done? I’m still real new at this and have big
dreams, eh?
i have’t seen any tutorials one how to do this in ROR, I’ve seen .Net
and coldfusion.

I saw this but not sure how to use it.
http://www.jhorman.org/FileSystemWatcher/index.html

thanks
John I.

On 8/15/06, John I. [email protected] wrote:

I’d like to monitor a folder and when someone drops a file in there I
can take the files name and add it to a database.

This is OS dependent - I’ve done it under linux using inotify, with a
daemon monitoring the folder and calling an “add_from_inotify” class
method in my model (via script/runner). Works very nicely. The code is
quite trivial; I could probably get permission to post it if you’re
interested.

martin

I’m on a windows platform.
coldfusion has event gateways in their enterprise ed, you can use them
in the developer mode though. they have some cool examples
http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001649.htm
look at the DirectoryWatcherGateway
I have found it stops running if I put more that 50 files into it. I
have a working example if you’re only doing a few files/folders. Since
we’re buiding something new the users want to drop their folders in
here. think of takeing your "my documents’ folder and having to move
it online. that would take forever. this way I can drop and forget and
then add indivudual files as needed. (i’m rambling)

for dot net I found these searches
http://www.google.com/search?q=c%23+directory+watch&hl=en&lr=
http://www.google.com/search?q=.NET+class+FileSystemWatcher&hl=en&lr=

I liked this but I haven’t had to get into .net yet.
this one can run as a service.
http://www.codeproject.com/csharp/FileWatcherWinServiceCSha.asp

FreeBSD has kqueue, and Windows has a built-in feature as well. I’ve
done
several polling routines using the opendir() syscall, and much prefer
kqueue. Webservers have well-written internal methods, but I don’t know
if
they expose an API.

But the question remains “how to do it in a platform-independant way
from
Ruby”. Polling will work, but if you want low-latency notification,
you’ll
burn cpu.

Don’t forget all the edge cases, like multiple files appearing in a
single
polling cycle, files deleted by external means (ftp), partial files
(in-transit ftp partials can be avoided by regex matching on a suffix to
which a file is renamed only upon completion), files edited or modified
in-place, files opened by a program (eg editor) that crashes, system
crashes
and reboots, big files filling the disk partition, file processing
(including exceptions) blocking new file notification, etc.

sounds like anouther use for backgroundrb…

2006/8/15, John I. [email protected]:

dreams, eh?
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Michael S. [email protected]

www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium