From: Robert Klemme Date: 2006-10-27T04:25:16+09:00 Subject: Re: Ruby fs watcher? Paul Lutus wrote: > 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. You rather need the mtime of the directory and only that - at least if you are interested in /new/ files only: require 'set' last = nil set = Set.new loop do current = File.mtime "." if last.nil? || last < current s = Dir["*"].to_set p s - set set = s last = current end sleep 1 end Test run: $ !ru ruby /cygdrive/c/Temp/watch.rb & [1] 1432 robert@fussel ~ $ # touch foo robert@fussel ~ $ # touch bar robert@fussel ~ $ # touch bar robert@fussel ~ $ touch baz robert@fussel ~ $ # Kind regards robert