Click here to Skip to main content
15,905,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to fI want to find a JS component to browser to a folder (Not a file). From https://stackoverflow.com/questions/43958335/select-folder-instead-of-single-file-input, someone uses the webkitdirectory. I have tried the code as shown below:
JavaScript
<input id="myInput" type="file" webkitdirectory directory multiple/>
// --------------------
HTMLInputElement.webkitdirectory = true;
var folder = document.getElementById("myInput");
folder.onchange = function () {
    var files = folder.files,
      len = files.length,
      i;
    for (i = 0; i < len; i += 1) {
        console.log(files[i]);
    }
}

However, the variable 'folder' is null. What's wrong in my code? Thanks.

What I have tried:

JavaScript - How to browser to a folder?
Posted
Comments
Richard MacCutchan 2-Nov-18 11:03am    
You should post your query in the StackOverflow question.
F-ES Sitecore 2-Nov-18 12:33pm    
What do you want to do with the folder?
Richard Deeming 2-Nov-18 12:57pm    
HTMLInputElement.webkitdirectory - Web APIs | MDN[^]
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
s yu 2-Nov-18 15:31pm    
Selecting a folder is for exporting files into that folder.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900