I am beginner in Python and try to write a script that would help the user to choose between existing files in a given folder and its sub-folders having a common format (bib files in that case). I use easygui module to prompt a choicebox but meet the following issue :
The filenames added to the list are not translated into options in the easygui choicebox.
import os.path
filesPathList = [] # bib file path list
fileNames = [] # file names list
for file in Path(path).rglob('*.bib'): #search recursively bib files in folders under path
if file:
filesPathList.append(os.path.join(path, file)) # Add file paths to their list
fileNames.append(os.path.basename(file)) # Add file names to their list
print(fileNames)
from easygui import *
choices = fileNames
msg = "choose your bib file"
title = "bib file options"
reply = choicebox(msg, choices = fileNames)
else:
print("no bib file found")
I would have expected a box with these kind of options : file1.bib / file2.bib / file3.bib, etc.
But what I get is :
File "C:\Program Files\Python310\lib\site-packages\easygui\boxes\choice_box.py", line 43, in choicebox mb = ChoiceBox(msg, title, choices, preselect=preselect, File "C:\Program Files\Python310\lib\site-packages\easygui\boxes\choice_box.py", line 125, in __init__ self.choices = self.to_list_of_str(choices) File "C:\Program Files\Python310\lib\site-packages\easygui\boxes\choice_box.py", line 184, in to_list_of_str raise ValueError('at least two choices need to be specified') ValueError: at least two choices need to be specifiedhow could it be possible to set different bib files found in folder path and subfolders as options in the easygui box ?
Thank you in advance for your advice