`title: File System Access 目录选择与批量持久化``categories: Web 开发/前端/数据管理``keywords: File System Access API,showDirectoryPicker,目录选择,OPFS,批量``description: 使用 showDirectoryPicker 选择目录并批量读取文件,桥接到 OPFS 或 IndexedDB 进行持久化与索引管理。`选择与遍历async function importDir() { const dir = await window.showDirectoryPicker(); for await (const [name, handle] of dir.entries()) { if (handle.kind === 'file') { const file = await handle.getFile(); const root = await navigator.storage.getDirectory(); const h = await root.getFileHandle(name, { create: true }); const w = await h.createWritable(); await w.write(await file.arrayBuffer()); await w.close(); } } }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.645684s