note 71328 deleted from function.unlink by sobak
| From: | sobak@php.net | Date: | Wed, 07 Dec 2016 11:31:51 +0000 |
| Subject: | note 71328 deleted from function.unlink by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208250@lists.php.net to get a copy of this message | ||
Note Submitter: torch at torchsdomain dot com
----
Here is simple function that will find and remove all files (except "." ones) that match
the expression ($match, "*" as wildcard) under starting directory ($path) and all other
directories under it.
function rfr($path,$match){
static $deld = 0, $dsize = 0;
$dirs = glob($path."*");
$files = glob($path.$match);
foreach($files as $file){
if(is_file($file)){
$dsize += filesize($file);
unlink($file);
$deld++;
}
}
foreach($dirs as $dir){
if(is_dir($dir)){
$dir = basename($dir) . "/";
rfr($path.$dir,$match);
}
}
return "$deld files deleted with a total size of $dsize bytes";
}