当前位置:网站首页>Tarfile decompress nested tar
Tarfile decompress nested tar
2022-06-12 18:42:00 【jjw_ whz】
The directory structure to be unzipped and the directory structure to be unzipped are as follows :
ILSVRC2012_img_train.tar
n01440764.tar
n01440764_18.JPEG
n01440764_36.JPEG
...
n01443537.tar
n01443537_2.JPEG
...
n01484850.tar
n01484850_17.JPEG
...
...
You want to decompress it to the following effect :
ILSVRC2012_img_train Folder
n01440764 Folder
n01440764_18.JPEG
n01440764_36.JPEG
...
n01443537 Folder
n01443537_2.JPEG
...
n01484850 Folder
n01484850_17.JPEG
...
...
Unzip the code as follows :
import os
import tarfile
file_path = './ILSVRC2012_img_train.tar'
file_name = file_path.split('/')[-1].split('.tar')[0]
os.mkdir(file_name) # Generate ILSVRC2012_img_train Folder
tar = tarfile.open(file_path)
tar.extractall(file_name) # Layer 1 decompression , Will be right ILSVRC2012_img_train.tar unpack
sub_tar_file_name_list = tar.getnames() # obtain ILSVRC2012_img_train.tar Subdirectories in
sub_file_name_list = []
for sub_tar_file_name in sub_tar_file_name_list:
sub_file_name_list.append(sub_tar_file_name.split('.tar')[0])
for dir_name in sub_file_name_list:
os.mkdir(file_name+'/'+dir_name) # Generate without .tar The catalog of
tar.close()
for extract_name in sub_tar_file_name_list:
sub_tar = tarfile.open('./'+file_name+'/'+extract_name)
sub_tar.extractall('./'+file_name+'/'+extract_name.split('.tar')[0]) # The second decompression
sub_tar.close()
os.system('rm -rf '+'./'+file_name+'/'+extract_name) # Delete the layer 2 tape after decompressing the layer 1 .tar The file of
# os.system('rm -rf file_path) If you want to ILSVRC2012_img_train.tar Also deleted, just use this
边栏推荐
- leetcode:6095. 强密码检验器 II【简单模拟 + 不符合直接False】
- Adjust CEPH cluster image source
- OpenGL shadow implementation (soft shadow)
- 2022.6.12 - leetcode. 89.
- Mise en œuvre de l'ACL réflexe dans le simulateur Cisco Cisco Packet Tracer
- 232-CH579M学习开发-以太网例程-TCP服务器(项目应用封装,局域网或广域网测试)
- 每日一博 - 微服务权限一二事
- Comparison of disk mapping tools for network disk and object cloud storage management
- no available service ‘null‘ found, please make sure registry config correct
- 深圳3月14日起全市停工停业7天居家办公心得|社区征文
猜你喜欢

被八股文害惨了。。。

CVPR 2022 Oral 大连理工提出SCI:快速、超强的低光照图像增强方法

VirtualLab基础实验教程-5.泊松亮斑

The Bean Validation API is on the classpath but no implementation could be found

liunx部署Seata(Nacos版)

【sql语句基础】——查(select)(单表查询)

C language operation database (SQLite3) call interface function

Problems that the sap Spartacus e-commerce cloud UI shipping method does not display in the unit test environment

【矩阵论 & 图论】期末考试复习思维导图

Review of MySQL (I): go deep into MySQL
随机推荐
Leetcode topic [string]-541- reverse string II
Implementing reflexive ACL in Cisco packet tracker
Basic SQL statement - select (single table query)
即时配送的订单分配策略:从建模和优化-笔记
笔记本电脑清灰打硅脂后,开机一直黑屏,如何破?
实验10 Bezier曲线生成-实验提高-控制点生成B样条曲线
Review of MySQL (4): sorting operation
Analyzing mobx responsive refresh mechanism from source code
SCI Writing - Methodology
Title 66: input 3 numbers a, B, C, and output them in order of size.
【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并
Voir les pages du site
Self made calculator (1 realized by Boolean logic operation unit and control unit programming)
Extracting strings with grep awk
Mysql ->>符号用法 Json相关
用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
Interior design style type, rendering 100 invitation code [1a12]
Leetcode topic [string] -151- flip words in string
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of swimming fins in the global market in 2022
kali通过iptables实现端口转发功能