Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 1st, 2001, 03:20 PM
JabezStone JabezStone is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 0 JabezStone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have built an e-greeting card engine using a simple database script and form-mailer. My problem is this...
Each greeting card that is sent creates a new .txt file on my server which stores variables. These text files are quickly adding up as popularity of my site increases, and I'm afraid that the burden of deleting the files to keep the server size down will quickly become too large of a task.

Is there a way to have my .cgi program check the directory for old files (30 days or more) and delete them?

This could either be a separate .cgi script that I can execute once a month, or preferrably some code to insert into my current .cgi that will perform this task each time a user generates a card.

Any help would be VERY appreciated!

Regards,

JabezStone

Reply With Quote
  #2  
Old May 1st, 2001, 07:04 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
Code:
$dir = '/path/to/data/dir';

opendir(DIR, $dir) or die $!;
    while(my $file = readdir(DIR)) {
          next if ($file !~ /\.txt/);

          unlink($dir.'/'.$file) if ((stat($dir.'/'.$file))[9] < (time() - 24 *30 * 3600));
    }
closedir(DIR);

I'd suggest putting it in a crontab to run once a day or something.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > CGI to delete old files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT