doomm4711 2019-07-04 10:18
浏览 74

如何从.tar存档文件中删除文件夹?

I want to delete a directory from a TAR archive file. I used the PharData class but I don't know how delete a directory.

I tried the Phardata::delete() method, but it only destroys empty folders in the TAR file and cannot delete other folders.

I tried the code below to delete folders from ZIP files and that works well. This code didn't work in PharData objects. How can I do it in the TAR file?

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
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭