[PyQt] PyQtMerger

Source: PyQtMerger.zip

以往在Linux底下要合併.001 .002 .003 ...這類的檔案都會在terminal底下使用cat這個指令來完成,但是一旦要合併的檔案數量很大時,輸入指令的工作就顯得很沒效率,為了快速解決這個問題我決定自行實做了類似HJsplit的程式,只是PyQtMerger只實現基本的合併部份,並沒有去實作分割的功能。

程式的概念很簡單,先判斷檔案的副檔名結構,再抓取要合併的檔案名稱串列,程式片段如下:
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

Orange - data analysis tool

Installation pip install orange3 Run orange python -m Orange.canvas