使用Python从仅具有基本名称的tarfile中提取文件 [英] Extracting file from tarfile with only basename using Python

查看:297
本文介绍了使用Python从仅具有基本名称的tarfile中提取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个"tafile",其中包含具有完整路径"/home/usr/path/to/file"的文件.当我将文件提取到curent文件夹时,它将递归创建完整路径. 有没有办法我可以仅使用基本名称提取文件.

I have a 'tafile' which contains files with complete path '/home/usr/path/to/file'. When I extract the file to the curent folder it creates the complete path recursively. Is there a way that I can extract the file with only the base name.

推荐答案

使用 TarFile.extractfile() 并将其写入您选择的文件中.

Use TarFile.extractfile() and write it into a file of your choice.

这篇关于使用Python从仅具有基本名称的tarfile中提取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆