Home > Backend Development > PHP Tutorial > Delete a directory and all files in the directory_PHP tutorial

Delete a directory and all files in the directory_PHP tutorial

WBOY
Release: 2016-07-20 11:01:41
Original
1059 people have browsed it

Delete the directory and all files in the directory * del_dir (delete path, 1 means deleting the data in the directory, 0 defaults to deleting this directory); ​

Delete the directory and all files in the directory
* del_dir (delete path, 1 means deleting data in the directory, 0 defaults to deleting this directory);
*/

function del_dir($dir_adds='',$del_def=0) {
$result = false;
If(! is_dir($dir_adds)){
          return false;
}
$handle = opendir($dir_adds);
While(($file = readdir($handle)) !== false){
If($file != '.' && $file != '..') {
$dir = $dir_adds . directory_separator . $file;
                 is_dir($dir) ? $this->del_dir($dir) : unlink($dir);
         }
}
​​ closedir($handle);
If($del_def==0){
$result = rmdir($dir_adds) ? true : false;
}else {
$result = true;
}
Return $result;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445411.htmlTechArticleDelete the directory and all files in the directory * del_dir (deleted path, 1 means deleting the data in the directory, 0 defaults to deletion this directory); delete the directory and all files in the directory *del_dir (delete path,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template