use TYPO3\CMS\Core\Utility\GeneralUtility; $directory = 'path/to/directory'; if (is_dir($directory)) { GeneralUtility::rmdir($directory, true); }This code first checks if the given path is a directory using is_dir() function. If it's a directory, it uses the rmdir() function to remove it. The second parameter of rmdir() is set to true to remove any subdirectories and files within that directory. The package library for this function is "typo3/cms-core". This is part of the TYPO3 CMS core and can be found in the composer.json file of a TYPO3 CMS installation.