GTK - PYTHON (filechooser-directorychooser)

GTK - PYTHON (filechooser-directorychooser)

if you have any FileChooser or DirectoryChooser window and you want to get the name of file or directory, you should be careful because python doesnt recognize the type of variable which you get with get_filename() function. you should use str(myVariable) function for no error.

for example: it brings you all mp3 files in a list

audio_files = get_existing_audio_files(str(self.dialogKlasorSec.get_filename()))

def get_existing_audio_files(data):    AUDIO_FILES_PATH = data    paths = glob.glob(os.path.join(AUDIO_FILES_PATH, ‘*.mp3’))    file_names=list()    for path in paths:        file_names.append(os.path.splitext(os.path.basename(path))[0])    return file_names