Recognizing the Arrival of a New File

Discussion in 'Python' started by Greg Lindstrom, Mar 8, 2005.

  1. Hello-
    I am writing an application where I need to recognize when a file
    arrives in a given directory. Files may arrive at any time during the
    course of the day. Do I set up a cron job to poll the directory every
    few minutes? Write a daemon to monitor the directory? Or is there some
    other more common/accepted way to perform this task? I'm using Python
    2.3 on Linux.

    Thanks for your help,
    --greg

    --
    Greg Lindstrom 501 975.4859
    Computer Programmer
    NovaSys Health
    Little Rock, Arkansas

    "We are the music makers, and we are the dreamers of dreams." W.W.
    Greg Lindstrom, Mar 8, 2005
    #1
    1. Advertising

  2. On Tue, 08 Mar 2005 08:43:04 -0600, rumours say that Greg Lindstrom
    <> might have written:

    >I am writing an application where I need to recognize when a file
    >arrives in a given directory. Files may arrive at any time during the
    >course of the day. Do I set up a cron job to poll the directory every
    >few minutes? Write a daemon to monitor the directory? Or is there some
    >other more common/accepted way to perform this task? I'm using Python
    >2.3 on Linux.


    The most common way to watch for a file or a directory change (in my experience)
    is to use the SGI fam (file alteration monitor); I think it has been ported to
    Linux. Otherwise, either way you describe is common use. Suggestion: first
    check for changes in the st_mtime of the directory, then search for the file
    existence.
    --
    TZOTZIOY, I speak England very best.
    "Be strict when sending and tolerant when receiving." (from RFC1958)
    I really should keep that in mind when talking with people, actually...
    Christos TZOTZIOY Georgiou, Mar 8, 2005
    #2
    1. Advertising

  3. Greg Lindstrom

    Chris Green Guest

    Greg Lindstrom <> writes:

    > Hello-
    > I am writing an application where I need to recognize when a file
    > arrives in a given directory. Files may arrive at any time during the
    > course of the day. Do I set up a cron job to poll the directory every
    > few minutes? Write a daemon to monitor the directory? Or is there some
    > other more common/accepted way to perform this task? I'm using Python
    > 2.3 on Linux.


    At my last job, we had a similar problem and I wanted to be able to
    check that the file was closed by the application that was putting it
    there (in that case the application was w32 writing to a share via
    samba).

    http://cmg.dok.org/cgi-bin/pyblosxom.cgi/python/linuxlease/

    Every other way I could find that relied on simple FS semantics had
    the possibility of reading a file partially.
    --
    Chris Green <>
    Eschew obfuscation.
    Chris Green, Mar 9, 2005
    #3
    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. Mike
    Replies:
    0
    Views:
    577
  2. Gordon Beaton

    Re: CHRIST: THE ARRIVAL

    Gordon Beaton, Dec 26, 2005, in forum: Java
    Replies:
    2
    Views:
    563
    Gordon Beaton
    Dec 26, 2005
  3. Per
    Replies:
    1
    Views:
    354
    Howard
    Apr 18, 2005
  4. Norm Goertzen

    New Arrival to Python

    Norm Goertzen, Aug 25, 2005, in forum: Python
    Replies:
    5
    Views:
    370
  5. Steve Holden
    Replies:
    1
    Views:
    639
    Giampaolo Rodola'
    Jan 26, 2009
Loading...

Share This Page