[Tutor] Hot Folders?
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Mon, 23 Oct 2000 23:33:39 -0700 (PDT)
On Mon, 23 Oct 2000, Scott Ralph wrote:
> I'd like to create a hot folder program in Python.. I'm still in the
> learning stage so any help would be great. Basically I would have a
> folder on my server that if and when a file hits it it will do
> something.. My problem is I'm not sure were to start. How can I code
> in my script a
>
> sort of watcher routine that will monitor this folder? Also how can I
> check if the file is actually done coping into the folder?
Wow! I've never done this before, so I don't know what's traditionally
done to do monitoring. One idea is to have your program sleep for a
while, and then every once in a while, check to see if things in your
directory are changing. Here's some pseudocode:
dircontents = getDirContents()
while 1:
newcontents = getDirContents()
if dircontents != newcontents:
doSomething()
dircontents = newcontents
sleep(1000)
This won't work unless we define getDirContents(), but that shouldn't be
too bad. You can do directory stuff with the 'os.path' module. From a
quick scanthrough, the 'dircache' module also looks useful for this stuff.
This looks like an interesting program! I hope this helps get you
started.