src/Composer/Util/Filesystem.php
public function removeDirectoryPhp($directory)
    {
        $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);

        foreach ($ri as $file) {
            if ($file->isDir()) {
                $this->rmdir($file->getPathname());
            } else {
                $this->unlink($file->getPathname());
            }
        }

        return $this->rmdir($directory);
    }
public function removeDirectoryPhp($directory)
    {
        $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);

        foreach ($ri as $file) {
            if ($file->isDir()) {
                $this->rmdir($file->getPathname());
            } else {
                $this->unlink($file->getPathname());
            }
        }

        return $this->rmdir($directory);
    }
public function removeDirectoryPhp ( $ directory ) { $ it = new RecursiveDirectoryIterator ( $ directory , RecursiveDirectoryIterator :: SKIP_DOTS ) ; $ ri = new RecursiveIteratorIterator ( $ it , RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ ri as $ file ) { if ( $ file -> isDir ( ) ) { $ this -> rmdir ( $ file -> getPathname ( ) ) ; } else { $ this -> unlink ( $ file -> getPathname ( ) ) ; } } return $ this -> rmdir ( $ directory ) ; }
Recursively delete directory using PHP iterators.

Uses a CHILD_FIRST RecursiveIteratorIterator to sort files
before directories, creating a single non-recursive loop
to delete files/directories in the correct order.

@param  string $directory
@return bool
Recursively delete directory using PHP iterators .