Created
August 16, 2011 19:00
-
-
Save miku/1149856 to your computer and use it in GitHub Desktop.
Watch directory for file changes and act.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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