Home > php教程 > php手册 > php中删除非空目录实现代码

php中删除非空目录实现代码

WBOY
Release: 2016-05-25 16:56:13
Original
967 people have browsed it
php删除目录及文件的文件原是就是先检查此目录下是否有文件,如果有,是文件夹的话就再调用此函数删除,如果是文件就直接调用 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) ;
}
?>



教程链接:

随意转载~但请保留教程地址★

Related labels:
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