FileSystemDirectoryHandle:entries() 方法

Baseline 2023
Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

备注: 此特性在 Web Worker 中可用。

FileSystemDirectoryHandle 接口的 entries() 方法返回一个异步迭代器,用于迭代调用此方法的 FileSystemDirectoryHandle 中的条目的键值对。键值对是一个 [key, value] 形式的数组。

语法

js
entries()

参数

无。

返回值

一个新的包含 FileSystemDirectoryHandle 中每个条目的键值对的异步迭代器。

异常

NotAllowedError DOMException

如果句柄的 PermissionStatus.stateread 模式下不是 'granted',则抛出此异常。

NotFoundError DOMException

如果未找到当前条目,则抛出此异常。

示例

使用 for await...of 循环能够简化迭代过程。

js
const dirHandle = await window.showDirectoryPicker();

for await (const [key, value] of dirHandle.entries()) {
  console.log({ key, value });
}

规范

Specification
File System
# api-filesystemdirectoryhandle-asynciterable

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
entries

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

参见