数据列分开, 显示数据大小

This commit is contained in:
life
2015-11-21 14:56:41 +08:00
parent 8c11aad97b
commit c29f6fc27e
3 changed files with 102 additions and 9 deletions

25
node_modules/common.js generated vendored
View File

@@ -291,5 +291,30 @@ var Common = {
fs.rmdirSync(path);
}
},
/**
* 得到目录下的文件大小
* @param {string} path 路径
* @param {boolean} isRecursive 是否递归子目录
* @return {number} 大小, 以KB为单位
*/
getFolderSize: function (path, isRecursive) {
var me = this;
var size = 0;
var fies;
if ( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file, index) {
var curPath = path + '/' + file;
var stat = fs.statSync(curPath);
if(stat.isDirectory() && isRecursive) {
size += me.getFolderSize(curPath, isRecursive);
} else {
size += stat.size / 1000;
}
});
}
return size;
}
};
module.exports = Common;