note 42399 modified in function.unlink by aidan
| From: | aidan@php.net | Date: | Thu, 08 Jul 2004 06:45:16 +0000 |
| Subject: | note 42399 modified in function.unlink by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72857@lists.php.net to get a copy of this message | ||
Here is a funciton to delete an entire directory tree. You can follow the call to deltree () with
rmdir() if you want to remove the base directory.
<?php
//Example usage:
deltree ($basedir.$dir); // base directory is now empty
rmdir ($basedir.$dir); // base directory is now gone.
function deltree($dir){
$d = dir($dir);
while($f = $d->read() ){
if($f != "." && $f != ".."){
if(is_dir($dir.$f)){
deltree($dir.$f."/");
rmdir($dir.$f);
} // if
if(is_file($dir.$f))
unlink($dir.$f);
}// if
}// while
$d->close();
}
?>
--was--
Here is a funciton to delete an entire directory tree. You can follow the call to deltree () with
rmdir() if you want to remove the base directory.
Example usage:
deltree ($basedir.$dir); // base directory is now empty
rmdir ($basedir.$dir); // base directory is now gone.
function deltree($dir){
$d = dir($dir);
while($f = $d->read() ){
if($f != "." && $f != ".."){
if(is_dir($dir.$f)){
deltree($dir.$f."/");
rmdir($dir.$f);
} // if
if(is_file($dir.$f))
unlink($dir.$f);
}// if
}// while
$d->close();
}
http://php.net/manual/en/function.unlink.php