簡體   English   中英

Python 3.6,Windows 10 .tar.gz提取無法正常工作

[英]Python 3.6, Windows 10 .tar.gz extraction not working

我已經嘗試了幾種不同的方法,但是似乎沒有得到任何結果。 以下是兩次嘗試將.tar.gz歸檔文件的內容提取到壓縮歸檔文件所在的文件夾中的兩種嘗試;

例如,我將從Windows文件夾中的test_file.tar.gz開始,最后以test_file.tar.gz結束,再加上其提取的內容。

打印語句顯示在第一種方法中,代碼正確地遍歷了存檔,但是我看不到任何提取的內容。

我究竟做錯了什么?

import tarfile
import os
import sys

    full_path = 'C:\Myfolder\test_file.tar.gz'

    if (full_path.endswith("tar.gz")):
        tar = tarfile.open(full_path, "r:gz")

        for item in tar:
            print(item)
            tar.extract(item)
        tar.close()


        with tarfile.open(full_path) as tar:
            print(full_path)
            tar.extractall()        
            tar.close()

我檢查了您的代碼,除了縮進以外,其他一切正常。

但是請檢查執行腳本或更改的文件夾

tar.extractall('c:\\Path\\To\\Extract') 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM