Skip to content

Instantly share code, notes, and snippets.

@cyberchao
Last active November 9, 2023 14:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberchao/b9f605dd8a2562b91458afe2d34a4ef9 to your computer and use it in GitHub Desktop.
Save cyberchao/b9f605dd8a2562b91458afe2d34a4ef9 to your computer and use it in GitHub Desktop.
批量解压
import os
import tarfile
import py7zr
from tqdm import tqdm
def unpack(rootdir):
# 7z文件存放路径
zdir = os.path.join(rootdir, '7zfiles')
# 最终文件路径
maindir = os.path.join(rootdir, 'mainfiles')
print('Unpack start...')
if not os.path.isdir(zdir):
os.mkdir(zdir)
if not os.path.isdir(maindir):
os.mkdir(maindir)
tarlist = list()
for filename in os.listdir(rootdir):
filepath = os.path.join(rootdir, filename)
if os.path.isfile(filepath):
tarlist.append(filepath)
for filepath in tqdm(tarlist):
with tarfile.open(filepath, 'r') as tar:
zfile = tar.getmembers()[0].name
tar.extractall(zdir)
zfilepath = os.path.join(zdir, zfile)
dirname = os.path.join(maindir, zfile.split('.')[0])
if not os.path.isdir(dirname):
os.mkdir(dirname)
with py7zr.SevenZipFile(zfilepath, mode='r', password='fulibl.net') as z:
z.extractall(dirname)
print('Unpack finished...')
if __name__ == '__main__':
# 下载源压缩包存放路径
rootdir = '/nas/download'
unpack(rootdir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment