如何仅使用原生javascript递归获取文件夹大小并以此形式输出:
dir1 (1000kb)<br>
— subDir1 (500kb)<br>
——— subFile1 (300kb)<br>
——— subFile2 (200kb)<br>
— subDir2 (500)<br>
——— subFile1 (500kb)<br>
我的代码:
const fs = require('fs');
function scaner(y,counter = ''){
counter += '-';
let y1 = fs.readdirSync(y);
for(let x of y1){
console.log(`${counter}` + x);
let stat = fs.statSync(y + x);
if(!stat.isFile()){
let path = y + x + '/';
scaner(path,counter);
}
}
}
scaner('./');