Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. FileSystemDirectoryEntry
  4. createReader()

FileSystemDirectoryEntry: createReader() method

TheFileSystemDirectoryEntry interface's methodcreateReader() returns aFileSystemDirectoryReader object which can be used to read the entries inthe directory.

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp