Request some help please
Bayzuldin Timur
bayt at max.net.ua
Sat Aug 24 18:29:38 EDT 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
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