I am trying to select multiple folders. I need the equivalent of askopenfilenames()
for directories, but only askdirectory()
exists, which only allows to select one folder.
Previously I found a custom script that did this for Matlab (uigetdir
).
Any way of doing this in Python?
I need to batch process files in about 50 folders at a time, selecting them one by one is not realistic.
Also, I'm not a programmer, just trying to process my geophysical data, wouldn't be able to "code it myself" as I've seen suggested in other places. Would have thought such a basic thing would be included in the basic functions.
Having had the same problem I developed my own solution. With this you can select one directory at a time then select cancel when you are finished.
The function the returns a list of the directories you have selected.
def fun_directory_selector(request_string: str, selected_directory_list: list, search_directory):
directory_path_string = filedialog.askdirectory(initialdir=search_directory, title=request_string)
if len(directory_path_string) > 0:
selected_directory_list.append(directory_path_string)
fun_directory_selector('Select the next Directory or Cancel to end',
selected_directory_list,
os.path.dirname(directory_path_string))
return selected_directory_list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With