Re: Check to remove file that are older than 1 week
| From: | Eric Bolikowski | Date: | Thu, 05 Feb 2004 18:56:24 +0000 |
| Subject: | Re: Check to remove file that are older than 1 week | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-176926@lists.php.net to get a copy of this message | ||
Hi
Here's a little function I made up for this:
<?php
function delete_old_files($dir, $time_limit = 0){
if(!$time_limit) $time_limit = 7*24*60*60;
if ($df = opendir($dir)) {
while (false !== ($file = readdir($df))) {
if ($file != "." && $file != "..") {
$last_modified = filemtime($file);
if(time()-$last_modified > $time_limit){
unlink($file);
}
}
}
closedir($df);
}
}
delete_old_files('.');
?>
Hope that's what you need.
Eric
"Yc Nyon" <ycnyon@pd.jaring.my> wrote in message
news:001401c3f7cf$8a1615e0$6f40ba66@domain...
> Hi,
>
> I want to delete files than are older than 1 week from a specific
directory.
> Anyone mind to share their code? Can't anything on phpbuilder on this.
>
> Regards
> Nyon