473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to delete 1 week old files based on date created

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 5898
numberwhun
3,509 Expert Mod 2GB
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
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 Expert Mod 2GB
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
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...
5
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
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...
9
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...
0
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...
3
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 =...
3
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....
7
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: ...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...
0
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,...

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.