'how to choose folder with html input file

I want to choose only folders when I'm clicking browse button. In my project I'm using IE for some reasons. I searched some forums but I didn't find any useful solution. After choosing a folder I want to show folder path in textbox. So is there any solution for this?



Solution 1:[1]

No.

The directory attribute is not supported in IE, and even where it is supported, the original path is not made available to JS.

Solution 2:[2]

First, from the MDN document, we can see that the webkitdirectory attribute not support IE browser. So we can't use input file to select the folder.

Besides, when using the input file element to upload a file, most browsers (include the IE11 browser) will give you only the file name, instead of the full path. If we using the value attribute to get the file name, it will give us a fake path, like: "C:\fakepath\uploadfile.text". This is the browser default behavior, in order to prevent inappropriate information disclosure.

To get the full file path in IE browser, we could enable the security setting in Internet Explorer (open Internet Options, select Security tab, click the "Custom level...", enable the "Include local directory path when uploading files to a server" option and click OK button to save the change), after that we could use the value property to get the upload file full path, then, you could according to it to get the folder.

[Note]Providing the full file path is regarded as a security vulnerability and is by default disabled. For security considerations, I suggest you not enable this option and use this method to display the folder.

Solution 3:[3]

You have to put an empty attributes for your input type file

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

Solution 4:[4]

You can choose only folders with input tag in html but in the end it will select all the files in that folder and there is no way you could get the file path in modern browsers(for security reasons). JS does'nt communicate with file system.

but if your primary concern is for users to select folders only, you can use this:

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

Hope this helps!!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quentin
Solution 2 Zhi Lv
Solution 3 Djb
Solution 4 Milan Lakhani