概述通过目录选择器与摘要计算,可以进行重复文件识别与重命名处理。遍历与重命名async function hash(file) { const buf = await crypto.subtle.digest('SHA-256', await file.arrayBuffer()); return Array.from(new Uint8Array(buf)).map(x=>x.toString(16).padStart(2,'0')).join(''); } async function renameInDir() { const dir = await window.showDirectoryPicker(); const map = new Map(); for await (const [name, h] of dir.entries()) { if (h.kind !== 'file') continue; const f = await h.getFile(); const hex = await hash(f); if (map.has(hex)) { const newName = `${hex}-${name}`; const nh = await dir.getFileHandle(newName, { create: true }); const w = await nh.createWritable(); await w.write(await f.arrayBuffer()); await w.close(); await dir.removeEntry(name); } else { map.set(hex, name); } } }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.978785s