Todaymade\Daux\GeneratorHelper::rmdir PHP Method

rmdir() public static method

Remove a directory recursively
public static rmdir ( string $dir )
$dir string
    public static function rmdir($dir)
    {
        $it = new \RecursiveDirectoryIterator($dir);
        $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($files as $file) {
            if ($file->getFilename() === '.' || $file->getFilename() === '..') {
                continue;
            }
            if ($file->isDir()) {
                rmdir($file->getRealPath());
            } else {
                unlink($file->getRealPath());
            }
        }
    }

Usage Example

Exemplo n.º 1
0
 protected function ensureEmptyDestination($destination)
 {
     if (is_dir($destination)) {
         GeneratorHelper::rmdir($destination);
     } else {
         mkdir($destination);
     }
 }
GeneratorHelper