/** * 获取文件夹大小,单位字节 * @param file 文件夹路径 */ let sumSize = 0;
public static getSpace(file:string) { //读取文件夹下内容 let files = fs.readdirSync(file); //遍历文件 files.forEach(function(item:any,index:any){ walk(file,item) }); function walk(file:string,filename:string){ let states = fs.statSync(file+'/'+filename); //是否是文件夹 if(states.isDirectory()){ IndexDao.getSpace(file+'/'+filename); }else{ let size = states.size;//文件大小,以字节为单位 sumSize +=size;//求和 } } return _.round(sumSize/1024/1024);//单位转换为MB }
typescript项目中,遍历文件夹获取文件夹大小总和
猜你喜欢
转载自www.cnblogs.com/zlicon/p/10535235.html
今日推荐
周排行