FileSystemWatcher
current release 1.0.0
Overview
Simple library for watching events occurring on a file system. The events watched are CREATED, MODIFIED and DELETED. This solution is (should be) platform independent. For example, you might use this inside of your server to monitor changes in your config files.
Example
watcher = FileSystemWatcher.new()
watcher.addDirectory("/inetpub/ftproot", "*.xml")
watcher.sleepTime = 10
watcher.start { |status,file|
if(status == FileSystemWatcher::CREATED) then
puts "created: #{file}"
elsif(status == FileSystemWatcher::MODIFIED) then
puts "modified: #{file}"
elsif(status == FileSystemWatcher::DELETED then
puts "deleted: #{file}"
end
}
watcher.join() # join to the thread to keep the program alive
Installation
Run 'ruby install.rb'. This will place the libraries in your ruby/lib/site_ruby directory. There are 2 files, filesystemwatcher.rb and servicestate.rb.
General Usage
Notes
If you know that your directory contains many many files consider creating multiple FileSystemWatcher(s). Each watcher only uses 1 thread so if the number of directories is large it could slow down notifications.
Also, if you know your files are large be careful with the useMD5 option since it must read the contents of each file to generate a hash.