Mostrar archivos y tamaños segun forlder en Nodejs
Mon Jun 03 2024 14:37:41 GMT+0000 (Coordinated Universal Time)
Saved by
@RobertoSilvaZ
const fs = require('fs');
const path = require('path');
function getFolderSize(folder) {
let totalSize = 0;
function calculateFolderSize(folderPath) {
const files = fs.readdirSync(folderPath);
files.forEach(file => {
const filePath = path.join(folderPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
calculateFolderSize(filePath);
} else {
totalSize += stats.size;
}
});
}
calculateFolderSize(folder);
return totalSize;
}
const folderPath = path.resolve(__dirname, 'node_modules');
const folderSize = getFolderSize(folderPath);
console.log(`Size of node_modules: ${(folderSize / 1024 / 1024).toFixed(2)} MB`);
content_copyCOPY
https://chatgpt.com/
Comments