From: Paul Lutus Date: 2006-10-27T03:50:23+09:00 Subject: Re: Ruby fs watcher? Jean-Etienne Durand wrote: > Hi, > > I wrote a script processing some files in a directory: each time there > is a new file in a given directory, I do something. So, my problem here > is to know when a new file arrived in the dir. > What I do now is to try to open the file in exclusive mode and do not > process the file if it fails, but polling just kills the cpu. This problem is easily solved, and in a portable way. You create a list of the files and their modification times, then sleep for some interval, then wake up and compare the stored modification times with the new ones, also test for any new files. Take action on any new or modified files. Maybe 25 lines of Ruby code. Be sure to sleep for an interval between tests, otherwise your script will hog the processor. -- Paul Lutus http://www.arachnoid.com