Skip to content

Instantly share code, notes, and snippets.

@caingougou
Created January 22, 2013 02:25
Show Gist options
  • Save caingougou/4591550 to your computer and use it in GitHub Desktop.
Save caingougou/4591550 to your computer and use it in GitHub Desktop.
Monitor file or folder changes
#!/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