两个步骤,定义一个应采用目录并递归返回所有文件和文件夹的功能,如下
async function listAllFilesAndDirs(dirHandle) {
const files = [];
for await (let [name, handle] of dirHandle) {
const {kind} = handle;
if (handle.kind === 'directory') {
files.push({name, handle, kind});
files.push(...await listAllFilesAndDirs(handle));
} else {
files.push({name, handle, kind});
}
}
return files;
}
然后从您的代码中调用此函数,如下
mercipour cette问题与l'peactréponse