473,700 Members | 2,539 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 5923
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
2750
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
13274
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
1914
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 would work if it's possible to do it by week without writing 52 seperate lines, one for each week which...
9
3416
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 advise any idea how to construct such conversion.
0
1225
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
10069
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)) < First_Date
3
13745
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 always confirm a delete action. There is also a consensus that the best way to do this is a template...
7
9046
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
1695
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 VBscript? dim strExcludedPC ServerFileSave="\\S1-admin-06\User Area\Save\" strComputer = "."...
0
8731
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 usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8649
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9081
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8931
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5904
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4408
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2032
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.