FileSystemDirectoryEntry: createReader() メソッド
FileSystemDirectoryEntry
インターフェイスの createReader()
メソッドは、これは、ディレクトリーの項目を読み取るために使用することができる、FileSystemDirectoryReader
オブジェクトを返します。
構文
js
createReader()
引数
なし。
返値
ディレクトリー項目を読み込むために使用することができる FileSystemDirectoryReader
オブジェクト。
例
この例では、指定した FileSystemDirectoryEntry
の項目をすべて読み取って配列で返す readDirectory()
という非同期関数を作成しています。
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;
}
これは、readEntries()
を繰り返し呼び出してディレクトリー内のすべての項目を取得し、各項目を配列に連結することで動作します。空の配列を返すと、すべての項目が読み込まれたことになり、ループが終わります。
仕様書
Specification |
---|
File and Directory Entries API # dom-filesystemdirectoryentry-createreader |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createReader |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.