Last active
November 9, 2023 14:46
-
-
Save cyberchao/b9f605dd8a2562b91458afe2d34a4ef9 to your computer and use it in GitHub Desktop.
批量解压
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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