From: Dale Martenson Date: 2002-03-26T11:25:03+09:00 Subject: RE: File change notification? >> Is there a straightforward way of getting notified when a file >> changes? In NT I can block a thread on the handle returned by >> FindFirstChangeNotification. Does something like this exist in Ruby? >> I'm currently using the Cygwin version but could be convinced to >> switch. Here is a little hack that might work for you. There may be a better way, but I am still learning Ruby myself. class FileCheck < Thread def initialize( filename, callback, checktime=2 ) currentModTime = File.stat(filename).mtime return super { while true if currentModTime < File.stat(filename).mtime then callback.call currentModTime = File.stat(filename).mtime end sleep(checktime) end } end end # Do this when the file changes def fcAction print "#{Time.now}: Something changed!!\n" end # Create a file check on the passed in argument fc = FileCheck.new( ARGV.shift, proc { fcAction } ) fc.run # do something useful for a while (hopefully not this) while true print "#{Time.now}: Nothing yet.\n" sleep(3) end