Folder Uploader Issue

I was using this snippet for folder uploading until I started getting an error where I was not able to make an executable for the application, the error seems to be related to this: Tkinter issue

Here’s my code snippet:

import streamlit as st
import tkinter as tk
from tkinter import filedialog

# Set up tkinter
root = tk.Tk()
root.withdraw()

# Make folder picker dialog appear on top of other windows
root.wm_attributes('-topmost', 1)

# Folder picker button
st.title('Folder Picker')
st.write('Please select a folder:')
clicked = st.button('Folder Picker')
if clicked:
    dirname = st.text_input('Selected folder:', filedialog.askdirectory(master=root))

Could anyone provide me with an alternative?

To upload all the files in a folder just drag and drop the folder into the file uploader.

If you can then please try running the above-provided code, you will get the idea of what I really want

I understand your code, but I don’t know for sure what you want. Being able to upload a folder? Being able to get the path to a folder, as the code does? Having a dedicated directory picker that doesn’t distract the user with other file names?

I only have an answer for the first one. You might be able to use HTML, javascript and the components API for the other two. But I have never seen anything like that so it might not be possible.

Oh ok
Thanks for input

Being able to upload a folder

Add a file uploader to the application. Drag and drop the folder into the file uploader. You can do it from the file manager or from the file picker.

A snippet please, specifically for folder/directory selection @andfanilo

Using that we can only select file, I want to select a directory

You cannot select a directory, but you can drag and drop a directory into the file uploader. That will result in the whole directory being uploaded so it fits the bill for being able to upload a folder.

For selecting a directory (directory picker), the only solution I know is the one you posted in the OP. But that can only work if the application and the browser are running in the same computer.

Drag and drop the file in the uploader it should work

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.