final public function deleteContents($folderpath, $filterByExtension = [], $filterByName = [],
                                         $filterExcludeMode = true, $recursive = true)
    {

        //1. Search $name as a folder or as a file
        if (!$this->is($folderpath)) { //if in path is a directory
            return false;
        }

        $dirh = @opendir($folderpath); //directory handler

        if ($dirh) {
            while (false !== ($file = readdir($dirh))) {
                // remove '.' and '..'
                if ($filterExcludeMode) {
                    //Excluding by name as in "file.ext"
                    if ($file == '.' || $file == '..' || in_array($file, $filterByName)) {
                        continue;
                    }
                    //Excluding extension
                    if (!empty($filterByExtension)) {
                        $fhandler = $this->getFile();
                        $extension = $fhandler->getExtension($file);
                        if (in_array($extension, $filterByExtension)) {
                            continue;
                        }
                    }
                }

                //The new path
                $newPath = $folderpath . DS . $file;
                //echo $newPath;

                //If newpath is a folder and we are deleting recursively
                if ($this->isFolder($newPath) && $recursive) {
                    $this->deleteContents($newPath, $filterByExtension, $filterByName, $filterExcludeMode, $recursive);
                }
                //Now unlink the file
                if (!static::delete($newPath)) {
                    static::setError("Could not delete {$newPath}");

                    return false;
                }
            }
            closedir($dirh);
        }

        //@TODO if long, get additional info for each path;

        return true;
    }
final public function deleteContents($folderpath, $filterByExtension = [], $filterByName = [],
                                         $filterExcludeMode = true, $recursive = true)
    {

        //1. Search $name as a folder or as a file
        if (!$this->is($folderpath)) { //if in path is a directory
            return false;
        }

        $dirh = @opendir($folderpath); //directory handler

        if ($dirh) {
            while (false !== ($file = readdir($dirh))) {
                // remove '.' and '..'
                if ($filterExcludeMode) {
                    //Excluding by name as in "file.ext"
                    if ($file == '.' || $file == '..' || in_array($file, $filterByName)) {
                        continue;
                    }
                    //Excluding extension
                    if (!empty($filterByExtension)) {
                        $fhandler = $this->getFile();
                        $extension = $fhandler->getExtension($file);
                        if (in_array($extension, $filterByExtension)) {
                            continue;
                        }
                    }
                }

                //The new path
                $newPath = $folderpath . DS . $file;
                //echo $newPath;

                //If newpath is a folder and we are deleting recursively
                if ($this->isFolder($newPath) && $recursive) {
                    $this->deleteContents($newPath, $filterByExtension, $filterByName, $filterExcludeMode, $recursive);
                }
                //Now unlink the file
                if (!static::delete($newPath)) {
                    static::setError("Could not delete {$newPath}");

                    return false;
                }
            }
            closedir($dirh);
        }

        //@TODO if long, get additional info for each path;

        return true;
    }
final public function deleteContents ( $ folderpath , $ filterByExtension = [ ] , $ filterByName = [ ] , $ filterExcludeMode = true , $ recursive = true ) { //1. Search $name as a folder or as a file if ( ! $ this -> is ( $ folderpath ) ) { //if in path is a directory return false ; } $ dirh = @ opendir ( $ folderpath ) ; //directory handler if ( $ dirh ) { while ( false !== ( $ file = readdir ( $ dirh ) ) ) { // remove '.' and '..' if ( $ filterExcludeMode ) { //Excluding by name as in "file.ext" if ( $ file == '.' || $ file == '..' || in_array ( $ file , $ filterByName ) ) { continue ; } //Excluding extension if ( ! empty ( $ filterByExtension ) ) { $ fhandler = $ this -> getFile ( ) ; $ extension = $ fhandler -> getExtension ( $ file ) ; if ( in_array ( $ extension , $ filterByExtension ) ) { continue ; } } } //The new path $ newPath = $ folderpath . DS . $ file ; //echo $newPath; //If newpath is a folder and we are deleting recursively if ( $ this -> isFolder ( $ newPath ) && $ recursive ) { $ this -> deleteContents ( $ newPath , $ filterByExtension , $ filterByName , $ filterExcludeMode , $ recursive ) ; } //Now unlink the file if ( ! static :: delete ( $ newPath ) ) { static :: setError ( "Could not delete {$newPath}" ) ; return false ; } } closedir ( $ dirh ) ; } //@TODO if long, get additional info for each path; return true ; }
Method to delete the contents of a folder

@param type $folderpath
@param type $filterByType
@param type $filterByName
@param type $filterExcludeMode
Method to delete the contents of a folder