Comment detail

ファイル更新の監視 (Nested Flatten)

This comment is reply for 391 kawauchi: (ファイル更新の監視). Go to thread root.

mtime を見ないで済むよう書き換えました。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
require 'rubygems'
require 'win32/ipc' # http://rubyforge.org/projects/win32utils
require 'win32/changenotify' # http://rubyforge.org/projects/win32utils
include Win32

exit if ARGV == []
filename = File.expand_path(ARGV[0])

flags = ChangeNotify::FILE_NAME | ChangeNotify::LAST_WRITE | ChangeNotify::SIZE
cn = ChangeNotify.new(File.dirname(filename), false, flags)

loop {
  cn.wait(){|sa|
    sa.each {|st|
      puts "modified!" if st.file_name == File.basename(filename)
    }
  }
}

Index

Feed

Other

Link

Pathtraq

loading...