Delete the file specified in the folder and all the following files

<?php
function delDir($dir) {

    // First delete the files in the directory:

    $ 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);

    // delete the current folder: 
    if ( rmdir ( $dir )) {
         return  true ;
    } else {
        return false;
    }
}

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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324837191&siteId=291194637