【发布时间】:2018-04-11 07:57:12
【问题描述】:
我正在尝试从压缩文件中复制所有 .txt 文件(该文件有 unknown_name_folders): .txt 文件位置 ---> my_path/?unknown_name_folder?/file.txt 我想做---> my_path/file.txt
我执行了这段代码,但是我遇到了这个错误:EOFError: Compressed file ended before the end-of-stream marker was达到。有什么想法吗?
file=my_path+"/"+fil
if file.endswith('.tar.gz'):
tarf = tarfile.open(file, "r:gz")
for info in tarf:
if info.name.endswith('.txt'):
print(info.name)
tar = tarfile.open(file) #extracting
tar.extractall()
tar.close()
code=os.system('cp ' + my_path+'/'+info.name +' '+ file)
【问题讨论】:
-
提取时不需要'gz'标志吗?
标签: python python-3.x python-2.7