File deletion after 72 hours of creation

ALEXURC at gmail.com ALEXURC at gmail.com
Thu Mar 29 16:40:58 EDT 2007


On Mar 29, 12:02 pm, s... at pobox.com wrote:
>     Alex> I'm looking for a simple method to delete a folder after 72
>     Alex> "Business hours" (saturday/sunday doesnt count) since its
>     Alex> creation. Note that This is on a linux system and I realize that
>     Alex> it will be the last modified time. These files wont be modified
>     Alex> since their creation.
>
>     Alex> Im very confused on how to work with the number easily.
>
> Take a look at the dateutil module.  Its relativedelta object has some
> weekday sense:
>
>    http://labix.org/python-dateutil
>
> Skip

Hey, thanks for the reply, I was able to accomplish it (somewhat ugly)
using the datetime module alone. Here is my code.
the part with the timestamp.file is just a plaintext file containg
"#year#month#day" that is created when my client side program copies
files into my directory.

Just posting the code so if anyone else is wondering how to do this
ever maybe they can find some of this useful:
---

#!/usr/bin/env python

import datetime
import os
today = datetime.date.today().toordinal()
serverFiles = os.listdir("/home/webserver/")
theDirList=[]
for xfile in serverFiles:
        if os.path.isdir("/home/webserver/" + xfile) == True:
                theDirList.append(xfile)


for xdir in theDirList:
        foo=open("/home/webserver/"+ xdir + "/timestamp.file",'r')
        parseMe = foo.readlines()
        fileDate=parseMe[0].split("#")
        fileYear = fileDate[1]
        fileMonth = fileDate[2]
        fileDay = fileDate[3]

        age_of_file = today -
datetime.date(int(fileYear),int(fileMonth),int(fileDay)).toordinal()
        true_age = age_of_file
        for i in range(age_of_file):
                d=
datetime.date(int(fileYear),int(fileMonth),int(fileDay)+i)
                ourDay = d.weekday()
                if ourDay == 5 or ourDay == 6:
                        true_age = true_age - 1

 print xdir + " : " + str(true_age) + " days old"




More information about the Python-list mailing list