It recursively removes the files and directories
@param $directory
@return void
483204
protected function remove($directory): void
    {
        $sourcePath = $this->packagePath . DS . $directory;

        if (!is_dir($sourcePath)) {
            return;
        }
        foreach ($iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator(
                $sourcePath,
                \RecursiveDirectoryIterator::SKIP_DOTS
            ),
            \RecursiveIteratorIterator::CHILD_FIRST
        ) as $item) {
            // path to copied file
            $current = PATH_ROOT . DS . $directory . DS . $iterator->getSubPathName();

            // remove empty directories
            if (is_dir($current)) {
                if (\count(scandir($current, SCANDIR_SORT_ASCENDING)) === 2) {
                    rmdir($current);
                    $this->installer->getIo()->write(
                        "  - Removed directory `{$iterator->getSubPathName()}`",
                        true,
                        IOInterface::VERBOSE
                    );
                } else {
                    $this->installer->getIo()->write(
                        sprintf(
                            '  - <comment>Skipped directory `%s`</comment>',
                            $directory . DS . $iterator->getSubPathName()
                        ),
                        true,
                        IOInterface::VERBOSE
                    );
                }
                continue;
            }

            // skip already removed files
            if (!is_file($current)) {
                continue;
            }

            if (md5_file($item) === md5_file($current)) {
                // remove file
                unlink($current);
                $this->installer->getIo()->write(
                    "  - Removed file `{$iterator->getSubPathName()}`",
                    true,
                    IOInterface::VERBOSE
                );
            } else {
                // or skip changed files
                $this->installer->getIo()->write(
                    "  - <comment>File `{$iterator->getSubPathName()}` has changed</comment>",
                    true,
                    IOInterface::VERBOSE
                );
            }
        }
    }
347088
protected function removeChildDirecotries(string $dir = null)
    {
        if (empty($dir)) {
            $dir = $this->cacheDir;
        }

        $success = true;
        $objects = new GlobIterator($dir);

        foreach ($objects as $object) {
            if (!is_dir("$dir/$object") && is_link("$dir/$object")) {
                $success = $this->recursiveRemove("$dir/$object") && rmdir($dir) && $success;
            }
        }

        return $success;
    }
773553
private function clearAttachments($dir)
    {
        if (!file_exists($dir)) {
            mkdir($dir, 0777, true);
        }

        $files = glob($dir.'/*');
        foreach ($files as $file) {
            if (is_file($file)) {
                unlink($file);
            }
        }
    }
35070
public function rmdir($directory = null)
    {
        if (\ftp_rmdir($this->_stream, $directory)) {
            return true;
        }

        $this->error = 'Failed to remove directory "'.$directory.'"';

        return false;
    }
675345
protected function makeDir($directory)
    {
        if (!$this->filesystem->isDirectory($directory)) {
            $this->filesystem->makeDirectory($directory, 0777, true);
        }
    }
685910
static function Delete($dir)
    {
        $files = self::GetFileSystemEntries($dir);
        
        foreach($files as $file)
        {
            $path = Path::Combine($dir, $file);
            switch(self::GetFileSystemEntryType($path))
            {
                case FileSystemEntryType::File():
                case FileSystemEntryType::Link():
                    unlink($path);
                    break;
                
                case FileSystemEntryType::Folder():
                    self::Delete($path);
                    break;
            }
        }
        rmdir($dir);
    }
751314
private function ftpDelete($directory)
    {
        // here we attempt to delete the file/directory
        if (!(@ftp_rmdir($this->ftp, $directory) || @ftp_delete($this->ftp, $directory))) {
            // if the attempt to delete fails, get the file listing
            $filelist = @ftp_nlist($this->ftp, $directory);

            // loop through the file list and recursively delete the FILE in the list
            foreach ($filelist as $file) {
                $this->ftpDelete($file);
            }

            // if the file list is empty, delete the DIRECTORY we passed
            $this->ftpDelete($directory);
        }
        return true;
    }
383835
public function ensureDirectory($directory)
	{
		if(!is_dir($directory))
		{
			$this->ensureDirectory(dirname($directory));
			echo "      mkdir ".strtr($directory,'\\','/')."\n";
			mkdir($directory);
		}
	}
783024
protected function clearDirectory($path)
    {
        $iterator = new \DirectoryIterator($path);

        /** @var \DirectoryIterator $fileinfo */
        foreach ($iterator as $fileinfo) {
            if ($fileinfo->isDot()) {
                continue;
            }

            if ($fileinfo->isFile() || $fileinfo->isLink()) {
                @unlink($fileinfo->getPathname());
            } elseif ($fileinfo->isDir()) {
                $this->clearDirectory($fileinfo->getPathname());
            }
        }
    }
504963
protected function _makeDirectory( $directory )
    {
        try
        {
            if ( !is_dir( $directory ) && !is_file( $directory ) && !is_link( $directory ) )
            {
                mkdir( $directory, 0755, true );
            }
        }
        catch ( \Exception $e )
        {
            $this->error( $e->getMessage() );
            die;
        }
    }
109833
public function removeDirectory(string $directory)
    {
        $search = rtrim(strtr($directory, '\\', '/'), '/');

        return $this->setDirectories(array_filter($this->getDirectories(), function ($item) use ($search) {
            return rtrim(strtr($item, '\\', '/'), '/') !== $search;
        }));
    }
462807
protected function makeDirs($directory)
	{
		foreach ($directory as $path) {
			if (!$this->files->isDirectory($this->getPath($path))){
				$this->files->makeDirectory($this->getPath($path), 0777, true);
			}
		}
	}
145839
public static void recursivelyDeleteDirectory(File directory) throws IOException {
    if (!directory.exists()) {
      return;
    }
    checkArgument(directory.isDirectory(), "Cannot recursively delete a non-directory");
    walkFileTree(directory.toPath(), new DeletionFileVisitor());
  }
682109
public static function removeDir(string $dir)
    {
        foreach (scandir($dir) as $file) {
            if ('.' === $file || '..' === $file) {
                continue;
            }
            if (is_dir($dir . '/' . $file)) {
                self::removeDir($dir . '/' . $file);
            } else {
                unlink($dir . '/' . $file);
            }
        }
        rmdir($dir);
    }
409955
public function clearDirectory($dir)
    {
        if (empty($dir) || !@is_dir($dir)) {
            return false;
        }

        $iterator = new \RecursiveDirectoryIterator($dir);
        $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current) {
            /** @var \SplFileInfo $current */
            $filename = $current->getBasename();
            // Check for files and dirs starting with "dot" (.gitignore, etc)
            return !($filename && $filename[0] === '.');
        });

        /** @var \SplFileInfo[] $listing */
        $listing = new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($listing as $item) {
            $path = $item->getPathname();
            $item->isDir() ? rmdir($path) : unlink($path);
        }
        return true;
    }
272716
public final void removeDirectory(final File directory) {
        try {
            FileUtils.deleteDirectory(directory);
        } catch (IOException e) {
            LOGGER.error("Unable to delete directory '{}'", directory);
        }
    }
731303
public static function recursiveDeleteDirectory(string $dirName): void {
		if (is_dir($dirName) && $dirArray = scandir($dirName)) {
			foreach ($dirArray as $k => $v) {
				if ($v !== '.' && $v !== '..') {
					if (is_dir($dirName . '/' . $v)) {
						static::recursiveDeleteDirectory($dirName . '/' . $v);
						rmdir($dirName . '/' . $v);
					}
					else
						unlink($dirName . '/' . $v);
				}
			}
		}
	}