使用EventMachine您可以觀察用於文件操作的文件夾,然後處理它們。
The Library rb-inotify does not fit as well。
# Create the notifier
notifier = INotify::Notifier.new
# Run this callback whenever the file path/to/foo.txt is read
notifier.watch("path/to/foo.txt", :access) do
puts "Foo.txt was accessed!"
end
# Watch for any file in the directory being deleted
# or moved out of the directory.
notifier.watch("path/to/directory", :delete, :moved_from) do |event|
# The #name field of the event object contains the name of the affected file
puts "#{event.name} is no longer in the directory!"
end
# Nothing happens until you run the notifier!
notifier.run
但是一旦文件被創建/上傳呢?有沒有辦法監控它,然後一旦發生,用其他地方存儲的腳本處理文件? – BigBoy1337
是的,你可以做任何你想whith文件在他notifier.watch | block | – rhasti