Home > php教程 > php手册 > 删除非空目录的php程序

删除非空目录的php程序

WBOY
Release: 2016-06-13 10:00:55
Original
962 people have browsed it

先检查此目录下是否有文件,如果有,是文件夹的话就再调用此函数删除,如果是文件就直接调用 unlink 删除,最后删除此目录。

 

 代码如下 复制代码

function removeDir($dirName)
{
    if(! is_dir($dirName))
    {
        return false;
    }
    $handle = @opendir($dirName);
    while(($file = @readdir($handle)) !== false)
    {
        if($file != '.' && $file != '..')
        {
            $dir = $dirName . '/' . $file;
            is_dir($dir) ? removeDir($dir) : @unlink($dir);
        }
    }
    closedir($handle);
 
    return rmdir($dirName) ;
}
?>

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template