
程式的概念很簡單,先判斷檔案的副檔名結構,再抓取要合併的檔案名稱串列,程式片段如下:
if(spPath[1] == ".001" or spPath[1] == ".000"):
self.outputPath = spPath[0]
self.ui.labExtensionValue.setText(".001 .002 .003 .004 .005 ...")
self.ui.labMergeFileValue.setText(self.outputPath)
for i in range(001,10):
ext = ".%03d" % i
if(os.path.exists(spPath[0]+ext)):
self.mergeList.append(spPath[0]+ext)
最後透過要合併的檔案串列資訊,搭配簡易的io操作就可以合併檔案了:
if (self.outputPath != ''):
self.ui.statusbar.showMessage('Merging...')
output = open(self.outputPath, 'wb')
for path in self.mergeList:
intput = open(path, 'rb')
while(True):
buff = intput.read(self.buffSize)
if(len(buff) == 0):
break
output.write(buff)
intput.close()
index += 1
self.ui.pBar.setProperty("value", float(index)/len(self.mergeList)*100)
output.close()
如果要讓此程式功能更完善,可以從副檔名的判斷著手,增加一些非數字的連續姓字母偵測能力,或者是把split的功能給整合進去吧!
No comments:
Post a Comment