Home > php教程 > php手册 > php 删除目录

php 删除目录

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:49:58
Original
1037 people have browsed it


 
/**********************************************************
清除指定目录内的文件
**********************************************************/
function clean_dir($path)        {
        if (!is_dir($path))        {
                if (is_file($path))        {
                        unlink($path);
                }
                return;
        }
        $p=opendir($path);
        while ($f=readdir($p))        {
                if ($f=="." || $f=="..") continue;
                clean_dir($path.$f);
        }
        rmdir($path);
        return;
}
/**********************************************************
删除指定目录下所有文件与子目录
**********************************************************/
function DeltreeDir($dir)  {
$dir = realpath($dir);
        if (!$dir || !@is_dir($dir))
                return 0;
        $handle = @opendir($dir);
        if ($dir[strlen($dir) - 1] != DIRECTORY_SEPARATOR)
                $dir .= DIRECTORY_SEPARATOR;
        while ($file = @readdir($handle))    {
                if ($file != '.' && $file != '..')         {
                        if (@is_dir($dir . $file) && !is_link($dir . $file))
                                DeltreeDir($dir . $file);
                        else
                                @unlink($dir . $file);
                }
        }
        closedir($handle);
        @rmdir($dir);
}

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template