FileSystemDirectoryEntry: createReader() method
TheFileSystemDirectoryEntry interface's methodcreateReader() returns aFileSystemDirectoryReader object which can be used to read the entries inthe directory.
In this article
Syntax
js
createReader()Parameters
None.
Return value
AFileSystemDirectoryReader object which can be used to read thedirectory's entries.
Examples
This example creates an async function calledreadDirectory(), which fetches all ofthe entries in the specifiedFileSystemDirectoryEntry and returns them inan array.
js
async function readDirectory(directory) { const dirReader = directory.createReader(); const entries = []; while (true) { const results = await new Promise((resolve, reject) => { dirReader.readEntries(resolve, reject); }); if (!results.length) { break; } for (const entry of results) { entries.push(entry); } } return entries;}This works by callingreadEntries() repetitively to get all the entries in the directory, concatenating each batch to the array. When it returns an empty array, all entries have been read, and the loop ends.
Specifications
| Specification |
|---|
| File and Directory Entries API> # dom-filesystemdirectoryentry-createreader> |