概述`showDirectoryPicker` 返回目录句柄,可通过异步迭代获取子项句柄,实现批量文件处理。需在安全上下文与用户触发下运行。用法/示例const dir = await window.showDirectoryPicker()
for await (const [name, handle] of dir) {
if (handle.kind === 'file') {
const file = await handle.getFile()
const text = await file.text()
}
}
工程建议明确处理规则与大小限制,避免性能问题;对大文件采用流式读取。要求用户触发与清晰授权文案;处理取消与访问错误。与 File System Access API 的文件写入配合,实现批量转换与导出。参考与验证MDN:File System Access — https://developer.mozilla.org/docs/Web/API/File_System_Access_APIweb.dev:Directory picker — https://web.dev/articles/file-system-access#directory_picker

发表评论 取消回复