Recognizing the Arrival of a New File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Lindstrom

    #1

    Recognizing the Arrival of a New File

    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 greg.lindstrom@ novasyshealth.c om
    NovaSys Health
    Little Rock, Arkansas

    "We are the music makers, and we are the dreamers of dreams." W.W.


  • Christos TZOTZIOY Georgiou

    #2
    Re: Recognizing the Arrival of a New File

    On Tue, 08 Mar 2005 08:43:04 -0600, rumours say that Greg Lindstrom
    <greg.lindstrom @novasyshealth. com> might have written:
    [color=blue]
    >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.[/color]

    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...

    Comment

    • Chris Green

      #3
      Re: Recognizing the Arrival of a New File

      Greg Lindstrom <greg.lindstrom @novasyshealth. com> writes:
      [color=blue]
      > 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.[/color]

      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).



      Every other way I could find that relied on simple FS semantics had
      the possibility of reading a file partially.
      --
      Chris Green <cmg@dok.org>
      Eschew obfuscation.

      Comment

      Working...