src/Koldy/Filesystem/Directory.php
public static function emptyDirectory(string $directory): void
    {
        if (is_dir($directory)) {
            foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $path) {
                if ($path->isFile()) {
                    if (!unlink($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                } else {
                    if (!rmdir($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                }
            }
        }
    }
public static function emptyDirectory(string $directory): void
    {
        if (is_dir($directory)) {
            foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $path) {
                if ($path->isFile()) {
                    if (!unlink($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                } else {
                    if (!rmdir($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                }
            }
        }
    }
public static function emptyDirectory ( string $ directory ) : void { if ( is_dir ( $ directory ) ) { foreach ( new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ directory , \ FilesystemIterator :: SKIP_DOTS ) , \ RecursiveIteratorIterator :: CHILD_FIRST ) as $ path ) { if ( $ path -> isFile ( ) ) { if ( ! unlink ( $ path -> getPathname ( ) ) ) { throw new FilesystemException ( "Unable to empty directory while emptying directory on path={$path->getPathname()}" ) ; } } else { if ( ! rmdir ( $ path -> getPathname ( ) ) ) { throw new FilesystemException ( "Unable to empty directory while emptying directory on path={$path->getPathname()}" ) ; } } } } }
Empty all directory content, but do not delete the directory

@param string $directory

@return void
@throws FilesystemException
Empty all directory content but do not delete the directory