获得所有文件
js
/**
* 获取所有文件
* @param {...string} paths
* @returns {AsyncGenerator<string, void, void>}
*/
async function* getAllFiles(...paths) {
const temp = [...paths];
while (temp.length) {
const dirPath = temp.pop();
for (const file of (await fss.readdir(dirPath)).map((file) =>
path.join(dirPath, file)
))
if ((await fss.stat(file)).isDirectory()) temp.push(file);
else yield file;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16