new file arrivals into a specific directory / folder

Discussion in 'Ruby' started by Dave Lilley, Sep 27, 2010.

  1. Dave Lilley

    Dave Lilley Guest

    greetings one and all,

    My need is this.
    Get my program to be executed when ever something new arrives into a
    directory.

    the data in the directory could be an email or it could be a file. most
    likely plain text the transport media unknown yet (transport could be
    using email or cellphone / digital RF into the PC ergo a file).

    frequency of scans for new arrivals may need to seconds or to minutes so
    variability here would be great here too.

    From reading months ago I wonder if notify or inotify or even cron would
    be good fit.

    Does anyone here know of a gem that could do this and if so please point
    me in the direction?

    Ruby currently using is 1.8.7 not sure if I'll take what i've done to
    1.9.x yet.
    as I've got to get my 1st project bedded in (this will be another
    project taking what i've done a step further).

    Or reason for not using ruby for this task of monitoring the directory?

    after doing a limited search of the list I've found filewatcher and
    directorywatcher just to name 2 at least.

    I know these are oldish but is there anything newer/better out there?

    I will be using the program on linux (specifically Kubuntu 10.04 but
    this maybe moved to a debian dedicated server) desktop pc.


    cheers,

    dave.
    --
    Posted via http://www.ruby-forum.com/.
    Dave Lilley, Sep 27, 2010
    #1
    1. Advertising

  2. Dave Lilley

    (r.*n){2} Guest

    On Sep 27, 6:43 am, Dave Lilley <> wrote:
    > greetings one and all,
    >
    > My need is this.
    >    Get my program to be executed when ever something new arrives intoa
    > directory.
    >
    > the data in the directory could be an email or it could be a file. most
    > likely plain text the transport media unknown yet (transport could be
    > using email or cellphone / digital RF into the PC ergo a file).
    >
    > frequency of scans for new arrivals may need to seconds or to minutes so
    > variability here would be great here too.
    >
    > From reading months ago I wonder if notify or inotify or even cron would
    > be good fit.
    >
    > Does anyone here know of a gem that could do this and if so please point
    > me in the direction?
    >
    > Ruby currently using is 1.8.7 not sure if I'll take what i've done to
    > 1.9.x yet.
    > as I've got to get my 1st project bedded in (this will be another
    > project taking what i've done a step further).
    >
    > Or reason for not using ruby for this task of monitoring the directory?
    >
    > after doing a limited search of the list I've found filewatcher and
    > directorywatcher just to name 2 at least.
    >
    > I know these are oldish but is there anything newer/better out there?
    >
    > I will be using the program on linux (specifically Kubuntu 10.04 but
    > this maybe moved to a debian dedicated server) desktop pc.
    >
    > cheers,
    >
    > dave.
    > --
    > Posted viahttp://www.ruby-forum.com/.


    One implementation that may work is to use a currency file (a hidden
    file say .currfile). For the very first run, get all the files and at
    the end touch this file (if it does not exist). So it is something
    like this:

    while (forever)
    do
    save the current timestamp
    if .currfile exists
    find all files newer than .currfile in directory
    else
    find all files
    end

    touch (create/update) .currfile with the saved timestamp.

    sleep for some time
    done

    Depending on how precise that you want the process to be, you may have
    to modify this a bit.

    This kind of use of currency file was done by news utility in unix to
    show only the news items (on command line) that the user has not
    already seen.
    (r.*n){2}, Sep 27, 2010
    #2
    1. Advertising

  3. [Note: parts of this message were removed to make it a legal post.]

    Morning Dave,

    On Mon, Sep 27, 2010 at 3:43 AM, Dave Lilley <> wrote:

    > greetings one and all,
    >
    > My need is this.
    > Get my program to be executed when ever something new arrives into a
    > directory.
    >


    Very straight forward here. Using the rb-notify library (
    http://github.com/nex3/rb-inotify)

    i = INotify::Notifier.new

    i.watch('/directory', :close_write) do |ev|
    puts "#{ev.name.to_s} just added"
    end

    i.run

    You could shell out or embed this in your app or whatever else you wanted
    but this will fire the block for every new file placed in the directory.

    John
    John W Higgins, Sep 27, 2010
    #3
  4. Dave Lilley

    Dave Lilley Guest

    John W Higgins wrote:
    > Morning Dave,
    >
    > On Mon, Sep 27, 2010 at 3:43 AM, Dave Lilley <> wrote:
    >
    >> greetings one and all,
    >>
    >> My need is this.
    >> Get my program to be executed when ever something new arrives into a
    >> directory.
    >>

    >
    > Very straight forward here. Using the rb-notify library (
    > http://github.com/nex3/rb-inotify)
    >
    > i = INotify::Notifier.new
    >
    > i.watch('/directory', :close_write) do |ev|
    > puts "#{ev.name.to_s} just added"
    > end
    >
    > i.run
    >
    > You could shell out or embed this in your app or whatever else you
    > wanted
    > but this will fire the block for every new file placed in the directory.
    >
    > John


    many thanks for the heads up think this was what I had read or was it in
    a repository and called lib-inotify ruby??

    what ever this was what I was looking for.

    by the way would cron be a good 2nd?

    i.e every X seconds / minutes / hours it spawns/executes my script to to
    check for new files / emails and then proceed to process them?

    dave.

    cheers,
    --
    Posted via http://www.ruby-forum.com/.
    Dave Lilley, Sep 29, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    7
    Views:
    18,522
    catherine sea
    Oct 28, 2010
  2. Replies:
    1
    Views:
    792
    Mark Rae
    Feb 26, 2006
  3. =?Utf-8?B?SmF2?=

    Is ViwState Page-Specific or UserControl-Specific

    =?Utf-8?B?SmF2?=, Aug 16, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    524
    =?Utf-8?B?SmF2?=
    Aug 16, 2006
  4. madhu
    Replies:
    0
    Views:
    403
    madhu
    Oct 5, 2006
  5. mazdotnet
    Replies:
    2
    Views:
    389
    Alexey Smirnov
    Oct 2, 2009
Loading...

Share This Page