watching a directory in ruby

后端 未结 6 1480
半阙折子戏
半阙折子戏 2020-12-14 01:04

We have an application that needs to process incoming files that are dropped into a directory. I am looking for the best way to do this.

We have been using a loopin

6条回答
  •  天涯浪人
    2020-12-14 01:42

    There's also the tiny filewatcher rubygem. The gem has no dependencies, contains no platform specific code and simply detects updates, delitions and additions by polling.

    require 'filewatcher'
    
    FileWatcher.new(["directory"]).watch() do |filename, event|
      if(event == :changed)
        puts "File updated: " + filename
      end
      if(event == :delete)
        puts "File deleted: " + filename
      end
      if(event == :new)
        puts "Added file: " + filename
      end
    end
    

提交回复
热议问题