0

So far I've been able to get only the file names from the browse button by using just jQuery and HTML file form. Here is my fiddle: http://jsfiddle.net/p42Wv/2/

MY ATTEMPT

$("#file").bind("change", function() {
var elem = document.getElementById("file");
var names = [];
for (var i = 0; i < elem.files.length; ++ i) {
   names.push(elem.files[i].name);
}
var names2 = names.join('\n');
$("#filename").val( names2 );
});

I get the file names as I'm supposed to BUT how do i get the Folder Names as well as the file names when I select a mixed list of files and folders in the "Browse" button?

EDIT:

NOTE: I'm looking for Folder Name and NOT the Folder Path. I've seen website such as Google Drive that lets user's select a WHOLE folder to upload. Isn't the mere extraction of folder names such an issue? If not, how does Google Drive for instance, access the subfiles of a folder and upload?

Thanks a lot, John

  • Hello, so it is not possible to get the folder name that I select through the browse button? That's a bit weird because I've seen websites (Google Drive) that lets you upload a whole folder. So i am wondering why JUST the folder name can't be somehow extracted!? :O – user3141741 Jun 11 '14 at 19:14
  • you can get folders on chrome only using a webkit-directory attribute in an , input.files[], and file.webkitRelativePath on each file. – dandavis Jun 11 '14 at 19:17
  • Could you please explain how Google Drive works on all browsers then? – user3141741 Jun 11 '14 at 19:19
  • People seem to have mistaken my question for FOLDER PATH and not FOLDER NAME and have marked it as a duplicate atrociously! A good look at the question wouldn't hurt :\ FYI to the community : https://support.google.com/drive/answer/2424368?hl=en – user3141741 Jun 11 '14 at 19:21
  • gdrive uses a java applet for non-chrome browsers... you can use jszip to unpack a deep/recursive zipped folder, but that's an un-wanted complication for sure... – dandavis Jun 11 '14 at 19:26
  • Thank you, can I get a link to how its done on Google Chrome? – user3141741 Jun 11 '14 at 19:29
  • https://www.google.com/search?q=firefox+folder+upload&gws_rd=ssl#q=firefox+%22folder+upload%22&safe=off&tbs=qdr:y – dandavis Jun 11 '14 at 19:35
  • How is it done for chrome along the lines of my fiddle? Thanks – user3141741 Jun 11 '14 at 19:41
  • file.webkitRelativePath on files. "webkitdirectory" attribute (pardon my typo). there is a more complicated way to get empty folders using a weird chrome folder api, but you'll have to google for info on that... – dandavis Jun 11 '14 at 19:50

0 Answers0