Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select folder instead of single file - input

I want the input type to be folder and not a single file. How can I select a folder instead of just a single file. Also how can I then access each file in that selected folder. I tried this to select a folder but didn't work. I am on chrome.

 <input id="myInput" type="file" style={{visibility: 'hidden'}} webkitdirectory directory multiple/>

enter image description here

like image 992
EdG Avatar asked May 13 '17 21:05

EdG


People also ask

How do I select a folder in electron?

In Electron, you use HTML for your views. Thus, if you want the user to select a directory from the UI, you can use a <input type="file" webkitdirectory /> , just like in a normal web app.


1 Answers

You are looking for the files property, which returns a filelist. Use length to get the number of files then use a for statement to do the same for all files, increasing the count by 1 each time

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]);
  }
}
 <input id="myInput" type="file" webkitdirectory directory multiple>
like image 83
alessandrio Avatar answered Nov 21 '22 15:11

alessandrio