Python PYQT转换文件

时间:2015-09-24 21:11:39

标签: python pyqt

尝试成为办公室英雄(失败)并创建一个转换目录中文件的gui。我很接近但是一旦选择了一个按钮到转换器就需要帮助传递一个目录..

def selectFile(self):


    self.listWidget.clear() # In case there are any existing elements in the list
    directory = QtGui.QFileDialog.getExistingDirectory(self, "Pick a folder")


    for file_name in os.listdir(directory):
        if file_name.endswith(".csv"):
            self.listWidget.addItem(file_name)
            print (file_name)

def convertfile(self, directory):

    directoryPath = directory
#################
    #^^Directory from selection above to be put as directory for this convertor
###################

    print directoryPath, ':'

    # process all non-master CSVs
    for fileLocated in directoryPath:
        if fileLocated.endswith(".csv") and 'master' not in fileLocated.lower():

            csvFilename = fileLocated
            strippedFileName =  os.path.splitext(csvFilename)[0]
            wavFileName =  directoryPath  + strippedFileName + ".wav"

            print strippedFileName

感谢任何帮助!

1 个答案:

答案 0 :(得分:2)

你不能为自己添加这样的dir吗?

class test(QtGui.QDialog):

    def __init__(self):
        self.directory = None

    def selectFile(self):
        self.listWidget.clear() # In case there are any existing elements in the list
        directory = QtGui.QFileDialog.getExistingDirectory(self, "Pick a folder")
        self.directory = directory

    def convertfile(self):
        directoryPath = self.directory