There is a directory /home/example/public_html/users/files/
. Within the directory there are subdirectories with random names like 2378232828923_1298295497
.
How do I completely delete the subdirectories which have creation date > 1 month?
There is a good script that I use to delete files, but it don't work with dirs:
$seconds_old = 2629743; //1 month old
$directory = "/home/example/public_html/users/files/";
if( !$dirhandle = @opendir($directory) )
return;
while( false !== ($filename = readdir($dirhandle)) ) {
if( $filename != "." && $filename != ".." ) {
$filename = $directory. "/". $filename;
if( @filectime($filename) < (time()-$seconds_old) )
@unlink($filename); //rmdir maybe?
}
}
you need a recursive function for this.