Help needed on config files

jvdb streamservenl at gmail.com
Wed Jan 31 16:58:28 CET 2007


Ok, with all your help and very useful hints, i managed to solve it!
thanks!
Now my program loops through the config file, and deletes the files
older than 7 days with a specified extension.
Here's my program:
#this project removes old log files

import os, time
from ConfigParser import ConfigParser
now=time.time()

cfg = ConfigParser()
cfg.read("projects.cfg")

#loop through the config file
for proj in cfg.sections():
    print ""
    #get the path where file files should be
    path = cfg.items(proj)[1][1]
    #get the filetype
    ftype = cfg.items(proj)[0][1]
    print "project: %s, path to old logfiles: %s" % (proj, path)
    dirList=os.listdir(path)
    # Now check if the file is not a dir and then check if the file is
older than 7 days
    for fname in dirList:
        if fname.endswith(ftype):
            pad = path+"\\"+fname
            if os.stat(pad).st_mtime < now - 7 * 86400:
                if os.path.isfile(pad):
                    os.remove(pad)
                    print "The file %s is deleted" % (fname)



===========
#projects.cfg
[ebiz_factuur]
dir=c:\customer\ebiz_factuur
type=.log
[test]
dir=c:\temp
type=.txt




More information about the Python-list mailing list