删除文件夹指定的文件和下面全部文件

<?php
function delDir($dir) {

    //先删除目录下的文件:

    $dh=opendir($dir);

    while ($file=readdir($dh)) {

        if($file!="." && $file!="..") {

            $fullpath=$dir."/".$file;

            if ($file == '.svn') {
                delFulldir($fullpath);
            }else{
                if(is_dir($fullpath)) {
                    delDir($fullpath);
                }
            }

        }

    }

    closedir($dh);
}

 function delFulldir($dir) {
    //先删除目录下的文件:
    $dh = opendir($dir);
    while ($file = readdir($dh)) {
        if($file != "." && $file!="..") {
            $fullpath = $dir."/".$file;
            if(!is_dir($fullpath)) {
                unlink($fullpath);
            } else {
                delFulldir($fullpath);
            }
        }
    }
    closedir($dh);

    //删除当前文件夹:
    if(rmdir($dir)) {
        return true;
    } else {
        return false;
    }
}

delDir("C:\wamp\www\dataOld");

猜你喜欢

转载自www.cnblogs.com/matengfei123/p/8945353.html