NFePHP\Common\Files\FilesFolders::removeFolder PHP Method

removeFolder() public static method

Apaga um diretorio e todo o seu conteúdo
public static removeFolder ( string $dirPath ) : boolean
$dirPath string
return boolean
    public static function removeFolder($dirPath)
    {
        $files = array_diff(scandir($dirPath), array('.', '..'));
        foreach ($files as $file) {
            if (is_dir("{$dirPath}/{$file}")) {
                self::removeFolder("{$dirPath}/{$file}");
            } else {
                if (!unlink("{$dirPath}/{$file}")) {
                    throw new Exception\RuntimeException("Falha! sem permissão de exclusão do arquivo {$dirPath}/{$file}");
                }
            }
        }
        if (!rmdir($dirPath)) {
            $msg = "Falha! sem permissão de exclusão do diretório {$dirPath}";
            throw new Exception\RuntimeException($msg);
        }
        return true;
    }

Usage Example

 public function testCreateFoldersSuccess()
 {
     $folderBase = dirname(dirname(dirname(__FILE__))) . '/fixtures/NFe';
     $resp = FilesFolders::createFolders($folderBase);
     $this->assertTrue($resp);
     $resp = FilesFolders::removeFolder($folderBase);
     $this->assertTrue($resp);
 }