Am 21.12.2010 20:17, schrieb Matty Sarro:
Hey everyone.
I'm in the midst of writing a parser to clean up incoming files,
remove extra data that isn't needed, normalize some values, etc. The
base files will be uploaded via FTP.
How does one go about scanning a directory for new files? For now
we're looking to run it as a cron job but eventually would like to
move away from that into making it a service running in the
background.
When You say cron, I assume you're running linux.
One approach would be to os.walk() the directory in question, and filling a
dict with the absolute name of the file as key and the output from stat() as content.
Then re-scan regularly and check for changes in mtime,ctime etc.

A less ressource consuming approach would be to use Linux' inotify infrastructure,
which can be used from python https://github.com/seb-m/pyinotify

And, your service is only an import away :-)

https://github.com/seb-m/pyinotify/blob/master/python2/examples/daemon.py
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to