note 71327 modified in function.glob by bobby
| From: | bobby@php.net | Date: | Wed, 22 Nov 2006 22:09:46 +0000 |
| Subject: | note 71327 modified in function.glob by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119998@lists.php.net to get a copy of this message | ||
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";
}
--was--
Here is simple function that will find and remove all files (except "." ones) 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";
}
http://php.net/manual/en/function.glob.php