Recognizing the Arrival of a New File

G

Greg Lindstrom

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 (e-mail address removed)
NovaSys Health
Little Rock, Arkansas

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

Christos TZOTZIOY Georgiou

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

Chris Green

Greg Lindstrom said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Postgres and SSL 1
ODBC Connection on Windows XP 0
Accessing Postgress from Windows 0
Sharing Base Class members 0
Using Paramiko 0
Help Installing Python 2.3.5 2
EDI x12 --> XML 1
Lots of pdf files 8

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top