You can use <input type="file"> with the attribute of the multiple attribute, the accept attribute is set to text/plain ; change event; FileReader loop, for .
var pre = document.querySelector("pre"); document.querySelector("input[type=file]") .addEventListener("change", function(event) { var files = event.target.files; for (var i = 0; i < files.length; i++) { (function(file) { var reader = new FileReader(); reader.addEventListener("load", function(e) { pre.textContent += "\n" + e.target.result; }); reader.readAsText(file) }(files[i])) } })
<input type="file" accept="text/plain" multiple /> <pre> </pre>
You can also use the webkitdirectory and allowdirs to load the directory on chrome, chromium; at night 45+ or firefox 42+, where dom.input.dirpicker preferable to true , see Firefox 42 for developers , Select and unzip files and / or folders for analysis . Please note: you can also drop folders from the file manager in the <input type="file"> element
var pre = document.querySelector("pre"); document.querySelector("input[type=file]") .addEventListener("change", function(event) { console.log(event.target.files) var uploadFile = function(file, path) {
<!DOCTYPE html> <html> <head> <script></script> </head> <body> <input type="file" webkitdirectory allowdirs directory /> <pre> </pre> </body> </html>
plnkr http://plnkr.co/edit/Y1XYd9rLOdKRHw6tb1Sh?p=preview
For ajax requests for chrome, chrome file: the local file system protocol can you run with the --allow-file-access-from-files flag --allow-file-access-from-files , see Jquery load (), which works only in firefox? .
In firefox, you can set security.fileuri.strict_origin_policy to false , see Security.fileuri.strict origin policy .
For a possible $.ajax() approach on chrome, chrome you can try
var path = "/path/to/drectory"; // `D:\`, `file:` var files = []; $.ajax({url:path, dataType:"text html"}) .then((data) => { // match file names from `html` returned by chrome, chromium // for directory listing of `D:\Finaltests\test1\new\places`; // you can alternatively load the "Index of" document and retrieve // `.textContent` from `<a>` elements within `td` at `table` of // rendered `html`; note, `RegExp` to match file names // could probably be improved, does not match space characters in file names var urls = $.unique(data.match(/\b(\w+|\d+)\.txt\b/g)); return $.when.apply($, $.map(urls, (file) => { files.push(file); // `\`, or `/`, depending on filesystem type return $.ajax({url:path + "/" + file , dataType:"text html"}) .then((data) => { // return array of objects having property set to `file` name, // value set to text within `file` return {[file]:data} }) })) }) .then((...res) => { console.log(res, files) })