import zipfile
def unzip_file(zip_src, dst_dir):
r = zipfile.is_zipfile(zip_src)
if r:
fz = zipfile.ZipFile(zip_src, 'r')
for file in fz.namelist():
fz.extract(file, dst_dir)
else:
print('This is not zip')
name = "Net_CDD2."
unzip_file(zip_src="./"+name, dst_dir="./")
import zipfile,os
with zipfile.ZipFile('yolo3_pytorch_master.zip','w') as target:
for i in os.walk('yolo3_pytorch_master'):
for n in i[2]:
target.write(''.join((i[0],'/',n)))
import tarfile
import os
def un_tar(file_name):
"""解压tar"""
print(file_name)
tar = tarfile.open(file_name)
names = tar.getnames()
temp_file_path = ''
if os.path.isdir(file_name + "_files"):
print('文件已存在')
temp_file_path = os.path.isdir(file_name + "_files")
else:
temp_file_path = os.mkdir(file_name + "_files")
print('创建一个新的文件名')
for name in names:
tar.extract(name, file_name + "_files/")
tar.close()
return temp_file_path
un_tar('VOCtrainval_11')