app/Services/HousekeepingService.php
private function deleteFileOrFolder(Filesystem $filesystem, string $path): bool
    {
        if ($filesystem->has($path)) {
            try {
                $metadata = $filesystem->getMetadata($path);

                if ($metadata['type'] === 'dir') {
                    $filesystem->deleteDir($path);
                }

                if ($metadata['type'] === 'file') {
                    $filesystem->delete($path);
                }
            } catch (Exception $ex) {
                return false;
            }
        }

        return true;
    }
private function deleteFileOrFolder(Filesystem $filesystem, string $path): bool
    {
        if ($filesystem->has($path)) {
            try {
                $metadata = $filesystem->getMetadata($path);

                if ($metadata['type'] === 'dir') {
                    $filesystem->deleteDir($path);
                }

                if ($metadata['type'] === 'file') {
                    $filesystem->delete($path);
                }
            } catch (Exception $ex) {
                return false;
            }
        }

        return true;
    }
private function deleteFileOrFolder ( Filesystem $ filesystem , string $ path ) : bool { if ( $ filesystem -> has ( $ path ) ) { try { $ metadata = $ filesystem -> getMetadata ( $ path ) ; if ( $ metadata [ 'type' ] === 'dir' ) { $ filesystem -> deleteDir ( $ path ) ; } if ( $ metadata [ 'type' ] === 'file' ) { $ filesystem -> delete ( $ path ) ; } } catch ( Exception $ ex ) { return false ; } } return true ; }
Delete a file or folder, if we can.

@param Filesystem $filesystem
@param string     $path

@return bool
Delete a file or folder if we can .