From: Park Heesob Date: 2008-04-15T22:21:15+09:00 Subject: Re: win32-changenotify and modifying a file Hi, ----- Original Message ----- From: "Tomek Paczkowski" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Tuesday, April 15, 2008 9:45 PM Subject: win32-changenotify and modifying a file > Hey! > > I'm working with win32-changenofity library to listen for any changes in > a directory. I'm interested in added, deleted and modified files. That's > my code: > > #------- > filter = ChangeNotify::FILE_NAME | ChangeNotify::DIR_NAME > abs_path = File.expand_path(dir) > ChangeNotify.new(abs_path, true, filter) do |cn| > cn.wait do |events| > events.each do |event| > puts(event.action, event.file_name) > end > end > end > #-------- > > The problem is when I modify file on disk, it's not reported. When I use > additional filters like SIZE or LAST_WRITE I get changes reported few > times. Is there some combination which will report file change only once? > > -- It's a feature of ChangeNotify. You could filter duplicate event like this: filter = ChangeNotify::FILE_NAME | ChangeNotify::DIR_NAME | ChangeNotify::LAST_WRITE abs_path = File.expand_path(dir) pre_event = nil ChangeNotify.new(abs_path, true, filter) do |cn| cn.wait do |events| events.each do |event| next if [event.action,event.file_name] == pre_event pre_event = [event.action,event.file_name] puts(event.action, event.file_name) end end end Regards, Park Heesob