How to load a file list in javascript?
How do I load a list of files from a specified folder in javascript?
update
Actua开发者_如何学Clly is from a Xul application, but I think anything for a local html file will work.. (it's a standalone app). And are resource files (images) I'm talking about..
It's possible within a Firefox plug-in and has been for years. See the following page on MDC: https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO
If the folder is user-selected you can use the HTML5 File[1] APIs to read the files:
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
document.querySelector('#files').onchange = function(e) {
var files = e.target.files; // FileList
var output = [];
for (var i = 0, f; f = files[i]; ++i) {
output.push('<li><b>', f.name, '</b> (',
f.type || 'n/a', ') - ', f.size, ' bytes</li>');
// TODO: Use FileReader to actually read file.
}
document.querySelector('#list').innerHTML = '<ul>' + output.join('') + '</ul>';
};
If you're talking about JS in a browser and accessing files on the client's machine, you can't. Javascript has no access to the filesystem for security reasons.
精彩评论