Created
January 22, 2013 02:25
-
-
Save caingougou/4591550 to your computer and use it in GitHub Desktop.
Monitor file or folder changes
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 'inotify' | |
require 'find' | |
require 'pp' | |
i = Inotify.new | |
t = Thread.new do | |
i.each_event do |ev| | |
p ev.name | |
p ev.mask | |
end | |
end | |
raise("Specify a directory") if !ARGV[0] | |
Find.find(ARGV[0]) do |e| | |
if ['.svn', 'CVS', 'RCS'].include? File.basename(e) | |
#or !File.directory? e | |
Find.prune | |
else | |
begin | |
puts "Adding #{e}" | |
i.add_watch(e, Inotify::CREATE | Inotify::DELETE | Inotify::MOVE) | |
rescue | |
puts "Skipping #{e}: #{$!}" | |
end | |
end | |
end | |
t.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment