Skip to content

Instantly share code, notes, and snippets.

@miku
Created August 16, 2011 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miku/1149856 to your computer and use it in GitHub Desktop.
Save miku/1149856 to your computer and use it in GitHub Desktop.
Watch directory for file changes and act.
#!/usr/bin/env ruby
require 'rubygems'
require 'directory_watcher'
dw = DirectoryWatcher.new '.'
dw.interval = 1.0
dw.add_observer do |*args|
args.each do |event|
if /file\d/ =~ event.path
`cat file1.txt file2.txt file3.txt > files-combined.txt`
puts "#{Time.now.strftime("%I:%M:%S")} \
Created files-combined.txt (since #{event.path} #{event.type})"
end
end
end
dw.start
gets # when the user hits "enter" the script will terminate
dw.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment