473,586 Members | 2,718 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 1941

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#da y" 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.t oday().toordina l()
serverFiles = os.listdir("/home/webserver/")
theDirList=[]
for xfile in serverFiles:
if os.path.isdir("/home/webserver/" + xfile) == True:
theDirList.appe nd(xfile)
for xdir in theDirList:
foo=open("/home/webserver/"+ xdir + "/timestamp.file" ,'r')
parseMe = foo.readlines()
fileDate=parseM e[0].split("#")
fileYear = fileDate[1]
fileMonth = fileDate[2]
fileDay = fileDate[3]

age_of_file = today -
datetime.date(i nt(fileYear),in t(fileMonth),in t(fileDay)).too rdinal()
true_age = age_of_file
for i in range(age_of_fi le):
d=
datetime.date(i nt(fileYear),in t(fileMonth),in t(fileDay)+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.c om <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#da y" 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.t oday().toordina l()
serverFiles = os.listdir("/home/webserver/")
theDirList=[]
for xfile in serverFiles:
if os.path.isdir("/home/webserver/" + xfile) == True:
theDirList.appe nd(xfile)
for xdir in theDirList:
foo=open("/home/webserver/"+ xdir + "/timestamp.file" ,'r')
parseMe = foo.readlines()
fileDate=parseM e[0].split("#")
fileYear = fileDate[1]
fileMonth = fileDate[2]
fileDay = fileDate[3]

age_of_file = today -
datetime.date(i nt(fileYear),in t(fileMonth),in t(fileDay)).too rdinal()
true_age = age_of_file
for i in range(age_of_fi le):
d=
datetime.date(i nt(fileYear),in t(fileMonth),in t(fileDay)+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','We d']:
cutOffDate = cutOffDate - (2 * a_day)

for f in os.listdir( pth ):
fname = os.path.join(pt h ,f)
if os.path.isfile( fname ) and os.path.getmtim e(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
3764
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. Actually i am running a WinME with ActivePerl 5.8.0, what i want to know is 1.What do you mean by "file creation (and deletion) is not atomic over NFS" ?
2
1833
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 in advance whether or not a particular deletion will succeed. Due to other pre-deletion actions, I cannot attempt the deletion and catch the...
3
1745
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 TXT24 folder and delete any text file that is over 24 hours old based on file's creation date. All the files in this folder will have random names, so...
5
1327
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 images which are then resized to two thumbnail sizes and the original file is then deleted - works fine. In another part of this application I wish to...
1
2168
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 year and 51 being the days since Jan 1st. If we run this application again on the same day it will append to the file already created earlier....
3
1672
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 deletion and then replace it with "x" or something that securely removes previoius data. My question is what objects, API calls, etc, etc do I use...
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 group was into it already and is so kind to share here his experience. I have put already much efforts into this subject googling around, but up...
1
2495
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 publishing my site I do not see why it has to delete all the other folders of my site, containing other stuff !!?? Why do not just replace the old...
8
2502
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 webservice. But at times the files are getting locked by a process. We are not able to delete the files. the error message is " Cannot accoss the file <file...
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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 we have to send another system
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.