Request some help please

Bayzuldin Timur bayt at
Sun Aug 25 00:29:38 CEST 2002

> I need to be able to watch a linux directory and remove all file that
> are over 4 housr old .  Is this possoble with python or should I just
> use perl to do it?
> C Lee

#! /usr/bin/env python2.1

import os, sys, time
from stat import *

def visit(arg, dir, names):
    for name in names:
        fullname = os.path.join(dir, name)
        mode = os.stat(fullname)[ST_MODE]
        if S_ISDIR(mode):	# This is a directory
        elif S_ISREG(mode):	
	    # if file older than 4 hours old then --> remove
            if os.path.getmtime(fullname)+14400 <= 
		print 'File '+fullname+' was removed.'
            print 'File unknown', fullname
if __name__ == '__main__':
    os.path.walk(sys.argv[1], visit, None)

More information about the Python-list mailing list