我想从TAR存档文件中删除目录。我使用了PharData类,但不知道如何删除目录。
我尝试了Phardata::delete()
方法,但是它只会破坏TAR文件中的空文件夹,而不能删除其他文件夹。
我尝试了下面的代码从ZIP文件中删除文件夹,效果很好。该代码在PharData对象中不起作用。如何在TAR文件中完成此操作?
private function deleteArchiveDirectory($directory){
// When archive object is ZipArchive`
if ($this->archiveObject instanceof ZipArchive) {
$numFiles = $this->archiveObject->numFiles;
$folderToDelete = $directory; //folder to delete relative to root
for ($i = 0; $i < $numFiles; $i++) {
$entryInfo = $this->archiveObject->statIndex($i);
if (substr($entryInfo["name"], 0,
strlen($folderToDelete)) == $folderToDelete) {
$this->archiveObject->deleteIndex($i);
}
}
}
// When archive object is PharData
if ($this->archiveObject instanceof PharData) {
// How can I do it enter code here
}
}