/** * Remove empty directories recursively up * @param string $dir * @param Mage_Connect_Ftp $ftp */ protected function removeEmptyDirectory($dir, $ftp = null) { if ($ftp) { if (count($ftp->nlist($dir)) == 0) { if ($ftp->rmdir($dir)) { $this->removeEmptyDirectory(dirname($dir), $ftp); } } } else { if (@rmdir($dir)) { $this->removeEmptyDirectory(dirname($dir), $ftp); } } }
/** * Remove empty directories recursively up * * @param string $dir * @param Mage_Connect_Ftp $ftp */ protected function removeEmptyDirectory($dir, $ftp = null) { if ($ftp) { if (count($ftp->nlist($dir)) == 0) { if ($ftp->rmdir($dir)) { $this->removeEmptyDirectory(dirname($dir), $ftp); } } } else { $content = scandir($dir); if ($content === false) { return; } if (count(array_diff($content, array('.', '..'))) == 0) { if (@rmdir($dir)) { $this->removeEmptyDirectory(dirname($dir), $ftp); } else { throw new RuntimeException('Failed to delete dir ' . $dir . "\r\n Check permissions"); } } } }