FileSystemDirectoryHandle:entries() 方法
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2023年3月.
备注: 此特性在 Web Worker 中可用。
FileSystemDirectoryHandle 接口的 entries() 方法返回一个异步迭代器,用于迭代调用此方法的 FileSystemDirectoryHandle 中的条目的键值对。键值对是一个 [key, value] 形式的数组。
语法
js
entries()
参数
无。
返回值
一个新的包含 FileSystemDirectoryHandle 中每个条目的键值对的异步迭代器。
异常
NotAllowedErrorDOMException-
如果句柄的
PermissionStatus.state在read模式下不是'granted',则抛出此异常。 NotFoundErrorDOMException-
如果未找到当前条目,则抛出此异常。
示例
使用 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> |
浏览器兼容性
Loading…