From: Phrogz Date: 2006-08-16T03:35:09+09:00 Subject: Re: building a log by watching a file Bil Kleb wrote: > So, I was thinking of turning on a "watcher" that > would save off inputs decks every time an edit is > detected. > > Anyone have a one-liner? Definitely not a one-liner, but I can offer: http://phrogz.net/RubyLibs/rdoc/files/DirectoryWatcher_rb.html With that, it'd be as easy as: edit_logger = Dir::DirectoryWatcher.new( 'directory/to/watch', 2 ) # Only look at certain files in the directory edit_logger.name_regexp = /\.fortran$/ edit_logger.on_modify = Proc.new{ |the_file, stats_hash| puts "Hey, #{the_file.inspect} just changed." # Do something cool here. } edit_logger.start_watching