nodejs统计文件/文件夹数量
const fs = require('fs'); const path = require('path'); const htmlList = []; const cssList = []; const jsList = []; let fileNum = 0 let filesNum = 0 function getFiles(dir) { const folders = fs.readdirSync(dir); folders.forEach((folderName) => { const folderOrFilePath = path.join(dir, folderName); const stats = fs.statSync(folderOrFilePath); if (stats.isDirectory()) { filesNum+=1 getFiles(folderOrFilePath); } else { console.log(folderOrFilePath) fileNum+=1 // if (/[\w]+\.html$/.test(folderOrFilePath)) { // htmlList.push(folderOrFilePath); // } // else if (/[\w]+\.(css|map)$/.test(folderOrFilePath)) { // cssList.push(folderOrFilePath); // } else { // jsList.push(folderOrFilePath); // } } }); } getFiles('C:\\Users\\15735\\Desktop\\文件夹'); console.log('文件夹数量:'+filesNum+',文件数量:'+fileNum) // console.log(`html: ${htmlList.length}`, `css: ${cssList.length}`, `js: ${jsList.length}`);
node 统计数量.js