I have been running a script that will will delete archive folders that are older than 14 days. I have been doing created. However there are times when the script will not run and my boses want the folders deleted but the name of the folder. The folders names are 28-Feb-12, etc.... How do use the name to subtract 14 days?
treyb 0 Newbie Poster
Recommended Answers
Jump to PostThis should give you some hints ...
# use Python module datetime # to check if a dated filename +14 days is older than todays date import datetime as dt # dated filename for test file_str = "28-Feb-12" # abbreviated month list month_abv = ['Jan','Feb','Mar','Apr', 'May','Jun','Jul','Aug', 'Sep','Oct','Nov','Dec'] …
Jump to PostYou must not compare strings but datetime instances
now_date = datetime.now() dir_date = datetime.strptime(fname, fm) del_date = now_date - timedelta(days = 14) if dir_date <= del_date : print "Folder %s is older than 14 days" % fname
All 5 Replies
Gribouillis 1,391 Programming Explorer Team Colleague
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
treyb 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
vegaseat commented: nice +14
treyb 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.