![](/img/trans.png)
[英]Untar files with python and extract certain files with tarfile.extractall() python
[英]python TarFile.extractall command deletes the files in the target directory
這是我們生產環境中的一段簡單代碼。 Python 2.7版
tar = tarfile.open(fileobj=pipe, mode='r|gz')
tar.extractall(d)
finally 塊也會關閉 tar 文件。
finally:
if tar:
tar.close()
但是,在 windows 上,觀察到目標目錄中的一些文件在 extractall() 之后被刪除。 這可能嗎? 有沒有人見過這樣的問題?
Windows 是 windows 2016
以我的經驗 tarfile.extractall() 會覆蓋文件和目錄。 如果您編輯一些提取的文件,然后再次運行 extractall(),您將獲得“原始”文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.