This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: win32-changenotify 0.3.0 released
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
I *finally* released win32-changenotify 0.3.0 today. I had to disallow blocks to the constructor due to the asynchronous nature of the code I used. Well, I didn't have to, but I had to alter it in one of two ways. I chose what I believed to be the more strict option.
Anyway, here's a Ruby code snippet for you to enjoy. This notifies you of any file name changes, or writes to any existing files:
require "win32/changenotify"
include Win32
filter = ChangeNotify::FILE_NAME | ChangeNotify::LAST_WRITE
cn = ChangeNotify.new("C:\\",false,filter)
# Wait up to 5 minutes for a change
cn.wait(300){ |cn_struct|
puts "Something changed"
puts "File: " + cn_struct.file_name
puts "Action: " + cn_struct.action
}
I know the Perl version can't do this. I'm pretty sure the Python version can't either (but it's been a while since I looked).