我可以提取一个包含几个压缩文件的zip文件夹但是我不知道如何在其中提取zip和gz文件而不重复相同的过程两次?
import zipfile,fnmatch,os
rootPath = zipDataDirectory
rootPath2 = workingDirectory
pattern = '*.zip'
pattern2 = '*.gz'
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
print(os.path.join(root, filename))
zipfile.ZipFile(os.path.join(root, filename)).extractall(os.path.join(root, os.path.splitext(filename)
我尝试了以下不起作用的代码
extensionZip = "*.zip"
extensionGz = "*.gz"
for item in os.listdir(workingDirectory):
if item.endswith(extensionZip):
zipfile.ZipFile(item).extractall
else:
gzip.GzipFile.extract(item)