public function recursivelyDeleteFromDirectory($baseDirectory)
    {
        if (!is_dir($baseDirectory)) {
            return;
        }

        $iterator = new \RecursiveDirectoryIterator($baseDirectory);
        $files = new \RecursiveIteratorIterator(
            $iterator,
            \RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $file) {
            $fname = $file->getFilename();
            if ($fname == '.' || $fname == '..') {
                continue;
            }

            if ($file->isDir()) {
                $this->recursivelyDeleteFromDirectory($file->getRealPath());
            } else {
                unlink($file->getRealPath());
            }
        }

        rmdir($baseDirectory);

        return;
    }
public function recursivelyDeleteFromDirectory($baseDirectory)
    {
        if (!is_dir($baseDirectory)) {
            return;
        }

        $iterator = new \RecursiveDirectoryIterator($baseDirectory);
        $files = new \RecursiveIteratorIterator(
            $iterator,
            \RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $file) {
            $fname = $file->getFilename();
            if ($fname == '.' || $fname == '..') {
                continue;
            }

            if ($file->isDir()) {
                $this->recursivelyDeleteFromDirectory($file->getRealPath());
            } else {
                unlink($file->getRealPath());
            }
        }

        rmdir($baseDirectory);

        return;
    }
public function recursivelyDeleteFromDirectory ( $ baseDirectory ) { if ( ! is_dir ( $ baseDirectory ) ) { return ; } $ iterator = new \ RecursiveDirectoryIterator ( $ baseDirectory ) ; $ files = new \ RecursiveIteratorIterator ( $ iterator , \ RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ files as $ file ) { $ fname = $ file -> getFilename ( ) ; if ( $ fname == '.' || $ fname == '..' ) { continue ; } if ( $ file -> isDir ( ) ) { $ this -> recursivelyDeleteFromDirectory ( $ file -> getRealPath ( ) ) ; } else { unlink ( $ file -> getRealPath ( ) ) ; } } rmdir ( $ baseDirectory ) ; return ; }
Recursively delete files and folders, when given a base path
@param string $baseDirectory
@return void
Recursively delete files and folders when given a base path