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.

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


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
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

I liked this but I haven’t had to get into .net yet.
this one can run as a service.

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

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

Don’t forget all the edge cases, like multiple files appearing in a
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
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]

Michael S. [email protected] - Weltraum-Browsergame im Alpha-Stadium