Re: Help needed on config files
- From: "jvdb" <streamservenl@xxxxxxxxx>
- Date: 31 Jan 2007 07:58:28 -0800
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
.
- References:
- Help needed on config files
- From: jvdb
- Help needed on config files
- Prev by Date: Re: another newbie question: why should you use "*args" ?
- Next by Date: Re: "Correct" db adapter
- Previous by thread: Re: Help needed on config files
- Next by thread: another newbie question: why should you use "*args" ?
- Index(es):