Delete a file or folder, if we can.

@param Filesystem $filesystem
@param string     $path

@return bool
960225
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;
    }
857573
public static function deleteFolder($path) 
	{
		if(file_exists($path)) {
			$fh = dir($path);
			//print_r($fh);
			while (false !== ($files = $fh->read())) {
				/*
				echo $fh->path.'/'.$files."\n";
				chmod($fh->path.'/'.$files, 0755);
				if(@unlink($fh->path.'/'.$files))
					echo '1'."\n";
				else
					echo '0'."\n";
				*/
				@unlink($fh->path.'/'.$files);
			}
			$fh->close();
			@rmdir($path);

			return true;

		} else 
			return false;
	}
1097420
public static function removeDirectory($path) {
        if (is_dir($path))
            $dir = opendir($path);
        if (!$dir)
            return false;
        while ($file = readdir($dir))
            if (!self::isDot($file)) {
	            if (!is_dir("$path/$file"))
                    unlink("$path/$file");
	            else
                    self::removeDirectory("$path/$file");
            }
        closedir($dir);
        rmdir($path);
        return true;
    }
1155120
public function delete($path)
    {
        $result = Uploader::destroy($path, ['invalidate' => true]);

        return is_array($result) ? $result['result'] == 'ok' : false;
    }
1089039
public function delete($recursive = false)
    {
        $fs = FileSystem::getFileSystem();
        if ($fs->canDelete($this) !== true) {
            throw new IOException("Cannot delete " . $this->path . "\n");
        }

        $fs->delete($this, $recursive);
    }
1373586
public function delete($paths)
		{
			$paths = Arrays::is($paths) ? $paths : func_get_args();

			$success = true;

			foreach ($paths as $path) { if ( ! @unlink($path)) $success = false; }

			return $success;
		}
981173
public function delete($path): bool
    {
        $result = false;
        $parts = $this->split($path);

        $name = array_shift($parts);
        if (!count($parts)) {
            if (isset($this->ownData[$name])) {
                unset($this->ownData[$name]);
                $result = true;
            }
        } elseif (isset($this->subTrees[$name])) {
            $subtree = $this->subTrees[$name];
            $result = $subtree->delete($parts);
            if ($result && !$subtree->count()) {
                unset($this->subTrees[$name]);
            }
        }

        return $result;
    }
742968
public function deleteOnce( string $path ): bool
	{
		try {
			if( ! @ unlink( $path ) ) throw new ErrorException;
		}
		catch( ErrorException $e )
		{
			return false;
		}

		return true;
	}
1129754
public function listContents($filesystem, $path = '')
    {
        $this->set([
            '_serialize' => [
                'directoryContents',
            ],
            'directoryContents' => $this->filesystem($filesystem)->listContents($path),
        ]);
    }
1129313
private static boolean deleteIfExists(FileSystem fileSystem, Path path, boolean recursive)
    {
        try {
            // attempt to delete the path
            if (fileSystem.delete(path, recursive)) {
                return true;
            }

            // delete failed
            // check if path still exists
            return !fileSystem.exists(path);
        }
        catch (FileNotFoundException ignored) {
            // path was already removed or never existed
            return true;
        }
        catch (IOException ignored) {
        }
        return false;
    }
520431
public function delete() {

		if(@unlink($this->getPath())) {
			$this->deleteCacheEntries();
			self::unsetInstance($this->getPath());
		}
		else {
			throw new FilesystemFileException("Delete of file '{$this->getPath()}' failed.", FilesystemFileException::FILE_DELETE_FAILED);
		}

	}
437834
public function delete($paths)
    {
        return $this->filesystem->delete(
            collect((array)$paths)
                ->map(function ($path) {
                    return $this->path($path);
                })
                ->values()
                ->all()
        );
    }
752055
public function delete($path)
    {
        try{
            $this->getOss()->deleteObject($this->bucket, $path);
            return true;
        }catch (OssException $e){

        }
        return false;
    }
1264246
public static function delete($path)
    {
        @set_time_limit((int) ini_get('max_execution_time'));

        // Sanity check
        if (!rtrim($path, '/\\')) {
            // Bad programmer! Bad Bad programmer!
            throw new FilesystemException(__METHOD__ . ': You can not delete a base directory.');
        }

        // Check to make sure the path valid and clean
        $path = Path::clean($path);

        // Is this really a folder?
        if (!is_dir($path)) {
            throw new \UnexpectedValueException(sprintf('%1$s: Path is not a folder. Path: %2$s', __METHOD__, $path));
        }

        // Remove all the files in folder if they exist; disable all filtering
        $files = static::files($path);

        if (!empty($files)) {
            File::delete($files);
        }

        // Remove sub-folders of folder; disable all filtering
        $folders = static::items($path);

        foreach ($folders as $folder) {
            if (is_link($folder)) {
                // Don't descend into linked directories, just delete the link.
                File::delete($folder);
            } elseif (is_dir($folder)) {
                static::delete($folder);
            }
        }

        // In case of restricted permissions we zap it one way or the other
        // as long as the owner is either the webserver or the ftp.
        if (@rmdir($path)) {
            return true;
        } else {
            $error = error_get_last();
            throw new FilesystemException($error['message'], $error['type']);
        }
    }
232015
public static function delete($path)
    {
        if (is_dir($path)) {
            Folder::delete($path);
        } elseif (is_file($path)) {
            File::delete($path);
        }

        return true;
    }
809022
public function deleteDirectory(string $path, bool $keepDirectoryStructure = false) : bool
    {
        if (!$this->isDirectory($path)) {
            return false;
        }

        $items = new FilesystemIterator($path);

        foreach ($items as $item) {
            if ($item->isDir()) {
                if (!$this->deleteDirectory($item->getRealPath())) {
                    return false;
                }
            } elseif ($item->isFile()) {
                if (!$this->deleteFile($item->getRealPath())) {
                    return false;
                }
            }
        }

        if (!$keepDirectoryStructure) {
            return rmdir($path);
        }

        return true;
    }
726439
public static function rmdir($path)
    {
        $files = array_diff(scandir($path), array('.', '..'));

        $filesystem = new Filesystem();

        foreach ($files as $file) {
            $file = $path . DIRECTORY_SEPARATOR . $file;

            if (!file_exists($file)) {
                continue;
            }

            try {
                $filesystem->remove($file);
            } catch (IOException $exception) {
                return false;
            }
        }

        return true;
    }