当前位置:网站首页>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
边栏推荐
- 每日一博 - 微服务权限一二事
- 实验10 Bezier曲线生成-实验提高-控制点生成B样条曲线
- leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】
- 基于STM32设计智能家居控制系统(OneNet)_2022
- SCI Writing - Methodology
- 【sql语句基础】——查(select)(单表查询)
- Analyzing mobx responsive refresh mechanism from source code
- SCI Writing - Results
- Difference between rxjs of() and of ({})
- 基于Halcon的矩形卡片【手动绘制ROI】的自由测量
猜你喜欢
论大型政策性银行贷后,如何数字化转型 ?-亿信华辰
【0008】无序列表
GD32F4xx控制DGUS 变量显示
Partial scratch and corrosion detection of bolts and screws based on Halcon
C语言学习——数据在内存中的存储
leetcode:6095. 强密码检验器 II【简单模拟 + 不符合直接False】
MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column
VirtualLab基础实验教程-6.闪耀光栅
Why my order by create_ Time ASC becomes order by ASC
C语言练习(4)——大数乘除
随机推荐
leetcode:6097. 替换字符后匹配【set记录 + 相同长度逐一查询】
2022.6.12-----leetcode.890
Hugo blog building tutorial
Pytest automated testing framework (II)
kali局域网ARP欺骗(arpspoof)并监听(mitmproxy)局域内其它主机上网记录
Voir les pages du site
C language operation database (SQLite3) call interface function
Summary of interview questions
Partial scratch and corrosion detection of bolts and screws based on Halcon
Title 66: input 3 numbers a, B, C, and output them in order of size.
Interior design style type, rendering 100 invitation code [1a12]
间隔两个月,我的第二次上榜纪念日【2022.6.2】
Review of MySQL (I): go deep into MySQL
C language learning -- data storage in memory
Two months later, my second listing anniversary [June 2, 2022]
tarfile解压嵌套tar
Introduction to service grid and istio - continued
觀察網站的頁面
Adjust CEPH cluster image source
VirtualLab基础实验教程-4.单缝衍射