public function deleteDirectory(string $path, bool $withFiles = false)
    {
        if( $path == '*' )
            $this->abort('Can not delete "*", please specify folder or file.');

        $files = glob($path . '/*');

        foreach ( $files as $file ) {
            if( is_file($file) && ! $withFiles ) return;
            is_dir($file) ? $this->deleteDirectory($file, $withFiles) : unlink($file);
        }
        if( is_dir($path) )
            try {
                rmdir($path);
                $this->info('Deleting folder: ' . $path);
            } catch ( \Exception $e ) {
                $this->comment('Can not delete ' . $path . ', it might contain hidden files, such as .gitignore');
            }
    }
public function deleteDirectory(string $path, bool $withFiles = false)
    {
        if( $path == '*' )
            $this->abort('Can not delete "*", please specify folder or file.');

        $files = glob($path . '/*');

        foreach ( $files as $file ) {
            if( is_file($file) && ! $withFiles ) return;
            is_dir($file) ? $this->deleteDirectory($file, $withFiles) : unlink($file);
        }
        if( is_dir($path) )
            try {
                rmdir($path);
                $this->info('Deleting folder: ' . $path);
            } catch ( \Exception $e ) {
                $this->comment('Can not delete ' . $path . ', it might contain hidden files, such as .gitignore');
            }
    }
public function deleteDirectory ( string $ path , bool $ withFiles = false ) { if ( $ path == '*' ) $ this -> abort ( 'Can not delete "*", please specify folder or file.' ) ; $ files = glob ( $ path . '/*' ) ; foreach ( $ files as $ file ) { if ( is_file ( $ file ) && ! $ withFiles ) return ; is_dir ( $ file ) ? $ this -> deleteDirectory ( $ file , $ withFiles ) : unlink ( $ file ) ; } if ( is_dir ( $ path ) ) try { rmdir ( $ path ) ; $ this -> info ( 'Deleting folder: ' . $ path ) ; } catch ( \ Exception $ e ) { $ this -> comment ( 'Can not delete ' . $ path . ', it might contain hidden files, such as .gitignore' ) ; } }
Deleting existing folder

@param string $path
@param bool $withFiles
Deleting existing folder