Search code examples
htmlreactjsfile-uploaddirectory

How to select an empty directory in ReactJS?


I want to select an empty directory/folder(not any file) for my project . I've tried

<input directory="" webkitdirectory="" type="file"/>

This selects the files inside the directory and shows the files which were selected.

If i select an empty directory, since there are no files inside it, after selection it shows 'No file chosen'

I want to select only an empty directory(not any files). How can I solve this?


Solution

  • There is no built in control in any mainstream browsers that would allow a user to easily select a folder. The closest thing there is would be <input type="file">, but that only allows you to select a single file in a folder, not the folder itself.

    The only other thing you can do is to create a control that the user will have to approve of before they can use it.

    Found the above answer from https://www.tek-tips.com/faqs.cfm?fid=5201