Request some help please

chen lee clob at ber.com
Sun Aug 25 01:24:37 CEST 2002


Thank you so much for the valuble information 

C. Lee

On Sun, 25 Aug 2002 01:29:38 +0300, Bayzuldin Timur <bayt at max.net.ua>
wrote:

>
>> 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
>            pass		
>        elif S_ISREG(mode):	
>	    # if file older than 4 hours old then --> remove
>            if os.path.getmtime(fullname)+14400 <= 
>time.mktime(time.localtime()):
>		os.remove(fullname)
>		print 'File '+fullname+' was removed.'
>        else:
>            print 'File unknown', fullname
>	    
>if __name__ == '__main__':
>    os.path.walk(sys.argv[1], visit, None)





More information about the Python-list mailing list