public static function recursiveRemove(string $dir, bool $complete = true)
    {
        $di = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
        $ri = new \RecursiveIteratorIterator($di, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($ri as $file) {
            $file->isDir() ?  rmdir($file) : unlink($file);
        }
        if ($complete) {
            rmdir($dir);
        }
        return true;
    }
public static function recursiveRemove(string $dir, bool $complete = true)
    {
        $di = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
        $ri = new \RecursiveIteratorIterator($di, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($ri as $file) {
            $file->isDir() ?  rmdir($file) : unlink($file);
        }
        if ($complete) {
            rmdir($dir);
        }
        return true;
    }
public static function recursiveRemove ( string $ dir , bool $ complete = true ) { $ di = new \ RecursiveDirectoryIterator ( $ dir , \ FilesystemIterator :: SKIP_DOTS ) ; $ ri = new \ RecursiveIteratorIterator ( $ di , \ RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ ri as $ file ) { $ file -> isDir ( ) ? rmdir ( $ file ) : unlink ( $ file ) ; } if ( $ complete ) { rmdir ( $ dir ) ; } return true ; }
Removes all files and directories in a directory. BE CAREFUL!

By default, this includes directory specified in `$dir`. Pass `false` to
the second argument to disable this behavior and leave `$dir` in place.

@see https://stackoverflow.com/a/24563703

@param string $dir
@param boolean $complete
@return boolean
Removes all files and directories in a directory . BE CAREFUL!