{{APIRef("File System API")}}{{Non-standard_header}}
The DirectoryReader
interface of the File System API lets you read the entries in a directory.
This interface has been abandonned: it was on a standard track and it proves not a good idea. Do not use it anymore.
About this document
This document was last updated on March 1, 2012 and follows the W3C Specifications (Working Draft) drafted on April 19, 2011.
This specification is pretty much abandoned, having failed to reach any substantial traction.
Basic concepts
The only method for this interface, readEntries()
is for listing all the files and folders in a directory. To list all the entries, you need to do the following:
- Call
direcoryEntry.createReader()
to create a new DirectoryReader. - Call
readEntries()
. - Continue calling
readEntries()
until an empty array is returned. You have to do this because the API might not return all entries in a single call.
Example
In the following code snippet from HTML5Rocks, we list all the entries in a directory.
// Taking care of the browser-specific prefixes.
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.directoryEntry = window.directoryEntry || window.webkitDirectoryEntry;
...
function toArray(list) {
return Array.prototype.slice.call(list || [], 0);
}
function listResults(entries) {
// To improve performance, we create document fragments,
// which are appended to the DOM only once.
// So only one browser reflow occurs.
var fragment = document.createDocumentFragment();
entries.forEach(function(entry, i) {
var img = entry.isDirectory ? 'img src=<"folder-icon.gif">' :
'img src=<"file-icon.gif">';
var li = document.createElement('li');
li.innerHTML = [img, '', entry.name, ''].join('');
fragment.appendChild(li);
});
document.querySelector('#filelist').appendChild(fragment);
}
function onInitFs(fs) {
var dirReader = fs.root.createReader();
var entries = [];
// Keep calling readEntries() until no more results are returned.
var readEntries = function() {
dirReader.readEntries (function(results) {
if (!results.length) {
listResults(entries.sort());
} else {
entries = entries.concat(toArray(results));
readEntries();
}
}, errorHandler);
};
// Start reading the directory.
readEntries();
}
// Creating a filesystem
window.requestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, errorHandler);
Method overview
void readEntries (EntriesCallback successCallback, optional ErrorCallback errorCallback); |
Method
readEntries()
Returns a list of entries from a specific directory. Call this method until an empty array is returned.
void readEntries ( in EntriesCallback successCallback, optional ErrorCallback errorCallback );
- successCallback
- Called once for every successful call to
readEntries()
. It delivers the next previously unreported set of entries in the associated directory until an empty array is returned. - errorCallback
- A callback indicating that there was an error reading from the directory.
Returns
void
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 13{{ property_prefix("webkit") }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatNo() }} | 0.16{{ property_prefix("webkit") }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
See also
Specification: {{ spec("https://dev.w3.org/2009/dap/file-system/pub/FileSystem/", "File API: Directories and System Specification", "WD") }}
Reference: File System API
Introduction: Basic Concepts About the File System API