-3

I am new to JavaScript hence all mess up with me this time.my doubt is I want to create a JavaScript function which can get the names of all the files in a folder.

Please share your knowledge to get me the basic understanding for this.

ElGavilan
  • 6,610
  • 16
  • 27
  • 36

2 Answers2

-2

Because of security, generally you cannot access local files, but in modern browsers you can access some limited files in the sandbox. Your question is completely answered here: local-file-access-with-javascript

Community
  • 1
  • 1
Dandelion
  • 744
  • 2
  • 13
  • 34
  • it sounds crazy *Because of security, generally you cannot access local files **how cant you access local files in javascript since java script is client-side language it can access local-files** [read file names in java](http://stackoverflow.com/questions/1844688/read-all-files-in-a-folder) –  Dec 29 '14 at 18:37
  • Please see my answer- with working code. – Max Heiber Jan 07 '15 at 18:06
-2

HTML:

<input type="file" id="files" name="files[]" multiple="" webkitdirectory="">

JS (modern browsers only):

var getFileNames=function(selectorForInput){
    var files=[].reduce.call(document.querySelector(selectorForInput).files,function(files,file){
        files.push(file.name);
        return files;
    },[]);
    return files;
};
getFileNames('#files');
Max Heiber
  • 14,346
  • 12
  • 59
  • 97