我有几个大的 zip 文件,其中包含我必须维护的目录结构。目前我正在使用解压它们
zip = zipfile.ZipFile(self.fileName)
zip.extractall(self.destination)
zip.close()
问题是这些过程可能需要 3-5 分钟以上,而且我没有收到任何反馈表明它们仍在工作。我想要做的是将当前正在解压缩的文件的名称输出到我的 gui 的状态栏。我的想法是这样的
zip = zipfile.ZipFile(self.fileName)
zipNameList = zipfile.namelist(self.fileName)
for item in zipNameList:
self.SetStatusText("Unzipping" + str(item))
zip.extract(item)
zip.close()
这样做的问题是它没有创建正确的目录结构。我不确定这是否是最好的方法。
我也在考虑使用 wx.progressdialog 但无法想出一种方法来让它显示 zip.extractall(filename) 的进度。
最佳答案
我得到了一个可以接受的解决方案 - 尽管我认为我更希望它最终能够线程化。
def unzipItem(self, fileName, destination)
print "--unzipItem--"
zip = zipfile.ZipFile(fileName)
nameList = zip.namelist()
#get the amount of files in the file to properly size the progress bar
fileCount = 0
for item in nameList:
fileCount += 1
#Built progress dialog
dlg = wx.ProgressDialog("Unziping files",
"An informative message",
fileCount,
parent = self,
)
keepGoing = True
count = 0
for item in nameList:
count += 1
dir,file = os.path.split(item)
print "unzip " + file
#update status bar
self.SetStatusText("Unziping " + str(item))
#update progress dialog
(keepGoing, skip) = dlg.Update(count, file)
zip.extract(item,destination)
zip.close()
关于python 解压缩文件并提供 wxPython 状态栏更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568439/