[Tutor] Hotfolder 1st attempt

Scott Ralph scott@zenplex.com
Mon, 06 Nov 2000 11:59:07 -0500

Hello,  I am a newbie and this is really my first attempt at writing
something useful for myself.  It's a simple hotfolder. Basically place a
file in and dosomething with it.  In the example it's a move to /tmp
using os.open.    I used some  example code from the stat library ref.
program called walker.  Just thought I'd get some feedback from the

#!/usr/bin/env python

import os, sys
from time import *
from stat import *

# Start loop  by passing in a folder to monitor.  Example:
./hotfolder.py /home/scott/in_coming
# Use if statement with a +20 seconds to compare against system clock.
Used to check if file modification has stopped when copying.

def getDirContents(dir):
  while 1:
      for f in os.listdir(dir):
           pathname = '%s%s' % (dir, f)
           mode = os.stat(pathname)[ST_MODE]
           t = time()
           f = os.stat(pathname)[ST_MTIME]
           if f+20 < t:
               os.popen('mv %s %s' % (pathname, '/tmp/'))
               print 'not yet'

if __name__ == '__main__':