Home >Backend Development >PHP Tutorial >php delete directory_PHP tutorial

php delete directory_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:47:29860browse


 
/***************************************************** ******
Clear files in the specified directory
*************************************************** ********/
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;
}
/***************************************************** ******
Delete all files and subdirectories in the specified directory
*************************************************** ********/
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);
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632872.htmlTechArticle/***************************************************** ****** Clear files in the specified directory****************************************** **********************/ function clean_dir($path) { i...
Statement:
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