473,545 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to delete 1 week old files based on date created

2 New Member
Can anyone help me to make a perl script that could delete 1 week old files based on the date created?

I made a folder: (August 16, 2008 to September 1, 2008)

08-16-08
08-17-08
08-18-08
08-19-08
08-20-08
08-21-08
08-22-08
08-23-08
08-24-08
08-25-08
08-26-08
08-27-08
08-28-08
08-29-08
08-30-08
08-31-08
09-01-08

I want to remain the folder from 09-01-08 to 08-26-08 and delete the old files from 08-25-08 to 08-16-08....

here's the scripts that i made..
Codes:

#!/usr/bin/perl

use Date::Pcalc qw(:all);

$cleanpath="/TestDelete";

($y, $m, $d)=Today();

$deduct=-12;

($y2, $m2, $d2) = Add_Delta_Days( $y, $m, $d, $deduct);

$prevdate="$m2-$d2-$y2";

for ($i=0;$i<5;$i++ )
{
$n=1;
($y2, $m2, $d2)= Add_Delta_Days( $y2, $m2, $d2, $n);


if($d2==1 || $d2==2 || $d2==3 || $d2==4 || $d2==5 || $d2==6 || $d2==7 || $d2==8 || $d2==9)
{
$d2="0".$d2;
}

if ($m2<10)
{
$m2="0".$m2;
}

$shorty=substr( $y2,2,3);

$ddate="$m2-$d2-$shorty";
`/usr/bin/find \"$cleanpath \" -name \"$ddate\" -exec rm -rf "{}" ';'`;
}

if i run my scripts it only deleted the folder :
08-21-08
08-22-08
08-23-08
08-24-08
08-25-08
but it should delete the 08-25-08 up to 08-16-08 :-(

I really need the scripts... thanks a lot...

perltest :-(
Sep 1 '08 #1
3 5910
numberwhun
3,509 Recognized Expert Moderator Specialist
Personally, I would have taken the dates and converted them to Unix time (which, if you don't know, is the number of seconds since January 1st, 1970.). If I remember right, its called epoch.

You get your reference which is todays date and convert it to epoch, then you use that result as a comparison to check the date of the other files.

Regards,

Jeff
Sep 1 '08 #2
testperl
2 New Member
Personally, I would have taken the dates and converted them to Unix time (which, if you don't know, is the number of seconds since January 1st, 1970.). If I remember right, its called epoch.

You get your reference which is todays date and convert it to epoch, then you use that result as a comparison to check the date of the other files.

Regards,

Jeff
Hi Jeff,

Can u provide a perl script that can delete 1 week old files? or any for loop condition that can delete 1 week old files...?

Hope you can help me :-)
thanks

perltest :-)
Sep 1 '08 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
Hi Jeff,

Can u provide a perl script that can delete 1 week old files? or any for loop condition that can delete 1 week old files...?

Hope you can help me :-)
thanks

perltest :-)
I could, but you wouldn't learn anything from it and plus, this isn't a scripting service. Instead, we help people like yourself learn how to do this type of stuff by doing.

I won't write the script for you, but I can provide you an example of what I was referring to. Give me some time to put it together for you and I will post it here.

Regards,

Jeff
Sep 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2746
by: Alistair | last post by:
IIS, Access 2000 I have a page that tabulates data from a DB, this data is items for sale, private ads. is there a way that at the same time it can automatically delete entries that are outside of a specific date..ie. more than a week old?? or should I run two queries seperately..one page which goes through the DB
5
13266
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
21
1892
by: .:mmac:. | last post by:
I have to update a page every week. I get the page ahead of time so I used the "scheduled includes" webbot in Frontpage only to find that I would have to refresh the page every week to have it work. That is silly, it should run by itself. so... I asked the question in the FP group and I was offered this pseudocode to do it by month which...
9
3402
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a period and 13 periods a year. normally 52 weeks per year but one 53-week a year every 6 years. The 53th week is included in period 13. Can someone...
0
1215
by: richardkreidl | last post by:
Let's say I have the following folder: C:\Archive\Data\Logs\ and within this folder are many files in this format: Cycle Run of Tuesday, February 01, 2005.html Cycle Run of Wednesday, February 02, 2005.html .. .. .. Cycle Run of Monday, February 28, 2005.html
3
10054
by: richardkreidl | last post by:
I have the following module that I delete old files based on how old they are: Sub Main() Dim First_Date As String = Date.Today.AddDays(-7) Dim Archive_Files() As String = System.IO.Directory.GetFiles("C:\Turnover") Dim Filtered As New ArrayList For x As Integer = 0 To Archive_Files.Length - 1 If File.GetLastWriteTime(Archive_Files(x)) <...
3
13728
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should...
7
9032
by: derekdeben | last post by:
Hi, I have created a report that totals the number of days it took a product to ship by percentage by a date range for a specific location. My data comes from a query with the following headers: I used a count iff to calculate the following headers in the report. This is a percent of the total number of packages.
4
1690
by: viper888 | last post by:
Hi to all, I'm the newly appointed network administrator in our office, and upon scanning all the PCs that are connected to the network, (by the way we're using a windows 2000 server) almost all of them have games. It was the department policy that no games must be installed in each PC. Can you guys help me with this? or can you modify this...
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7918
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
7436
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
5981
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5341
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
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1897
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
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
715
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.