473,508 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File deletion after 72 hours of creation

I'm looking for a simple method to delete a folder after 72 "Business
hours" (saturday/sunday doesnt count) since its creation. Note that
This is on a linux system and I realize that it will be the last
modified time. These files wont be modified since their creation.

Im very confused on how to work with the number easily.

Mar 29 '07 #1
3 1936

AlexI'm looking for a simple method to delete a folder after 72
Alex"Business hours" (saturday/sunday doesnt count) since its
Alexcreation. Note that This is on a linux system and I realize that
Alexit will be the last modified time. These files wont be modified
Alexsince their creation.

AlexIm 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
Mar 29 '07 #2
On Mar 29, 12:02 pm, s...@pobox.com wrote:
AlexI'm looking for a simple method to delete a folder after 72
Alex"Business hours" (saturday/sunday doesnt count) since its
Alexcreation. Note that This is on a linux system and I realize that
Alexit will be the last modified time. These files wont be modified
Alexsince their creation.

AlexIm 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(fil eDay)).toordinal()
true_age = age_of_file
for i in range(age_of_file):
d=
datetime.date(int(fileYear),int(fileMonth),int(fil eDay)+i)
ourDay = d.weekday()
if ourDay == 5 or ourDay == 6:
true_age = true_age - 1

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

Mar 29 '07 #3
On 29 Mar 2007 13:40:58 -0700, AL*****@gmail.com <AL*****@gmail.comwrote:
On Mar 29, 12:02 pm, s...@pobox.com wrote:
AlexI'm looking for a simple method to delete a folder after 72
Alex"Business hours" (saturday/sunday doesnt count) since its
Alexcreation. Note that This is on a linux system and I realize that
Alexit will be the last modified time. These files wont be modified
Alexsince their creation.

AlexIm 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(fil eDay)).toordinal()
true_age = age_of_file
for i in range(age_of_file):
d=
datetime.date(int(fileYear),int(fileMonth),int(fil eDay)+i)
ourDay = d.weekday()
if ourDay == 5 or ourDay == 6:
true_age = true_age - 1

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

--
http://mail.python.org/mailman/listinfo/python-list
You may have "over thought" the problem :)

(Not tested)
----------------------------------------------------------
import os, time

pth = '/home/webserver/'
a_day = 60*60*24
today = time.asctime().split()[0]
cutOffDate = time.time() - (3 * a_day)
if today in ['Mon','Tue','Wed']:
cutOffDate = cutOffDate - (2 * a_day)

for f in os.listdir( pth ):
fname = os.path.join(pth ,f)
if os.path.isfile( fname ) and os.path.getmtime(fname) < cutOffDate:
print fname # os.remove(fname)

------------------------------------------------------------------
Mar 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3755
by: Hugz | last post by:
Hello, And Thank you for taking time to help me.Myself Hugz.I am new to perl and want to write my own Scripts.But i can't understand how perl "rename" function and "file locking" works. ...
2
1820
by: Justin | last post by:
Hi all, Does anybody know a way, in VB.Net, I can discover the file locks on a file on the local machine. I have an application which needs to delete specific files, but I would like to verify...
3
1738
by: crjunk | last post by:
I have a folder named TXT24 on my web server that will contain multiple txt files. I want to add some code to the Session_Start event in my Global.aspx page that will scan all the files in the...
5
1321
by: BlueFrog | last post by:
Hi all, I'd appreciate some ideas on this as I've just spent the last 2 hours trying to solve it to no avail. I'm am building a web application which includes the functionality to upload...
1
2164
by: subaruwrx88011 | last post by:
I am new to c++. Here is my problem. When my application runs it creates a log file for that day containing application specific information. The file format is CCSI_2006_51.log with 2006 being the...
3
1669
by: A_Republican | last post by:
I am interested in writing my own secure file deletion program. I want to be able to read and write to my hard drive directly. My application will seach my hard drive for all locations marked for...
9
2230
by: Claudio Grondi | last post by:
I am aware, that it is maybe the wrong group to ask this question, but as I would like to know the history of past file operations from within a Python script I see a chance, that someone in this...
1
2488
by: pamela fluente | last post by:
Is there an option to avoid the deletion of the entire site when doing the deployment (Publish feature) ? Why on the heart it has to erase *everything* by default? This seems absurd! If am I...
8
2485
by: mailtofinny | last post by:
Hi This is my first post to this forum. I am struck up with a problem. We have a perl script which deals with creation/deletion of files. This perl script is trigerred through a java...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7331
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.