Click here to Skip to main content
15,939,960 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello Guys,

There is a Folder control in HTML5.
I have use it but can't be able to write Code with that control.


here's my code:-

<input type="file" id="folderUpload" webkitdirectory="" directory="" />
Posted
Comments
ZurdoDev 11-Jul-13 8:42am    
What's the problem?

1 solution

Passing multiple files with drag&drop:
HTML
<div id="dropzone"></div>
JavaScript
var dropzone = document.getElementById('dropzone');
dropzone.ondrop = function(e) {
  var length = e.dataTransfer.files.length;
  for (var i = 0; i < length; i++) {
    var file = e.dataTransfer.files[i];
    ... // do whatever you want
  }
};


How to handle dropped folders
To handle a drop of multiple folders, you need to change the way you handle dropped objects:
HTML
<div id="dropzone"></div>
JavaScript
var dropzone = document.getElementById('dropzone');
dropzone.ondrop = function(e) {
  var length = e.dataTransfer.items.length;
  for (var i = 0; i < length; i++) {
    var entry = e.dataTransfer.items[i].webkitGetAsEntry();
    if (entry.isFile) {
      ... // do whatever you want
    } else if (entry.isDirectory) {
      ... // do whatever you want
    }
  }
};


Cheers,
Edo
 
Share this answer
 
v2

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