本帖最后由 pcl_test 于 2016-4-29 21:20 编辑
- /*&cls
- @echo off
- (for /f "delims=" %%a in ('dir /a-d/b/s^^^|find /v "%~nx0"') do @echo;%%~nxa*%%~za)|cscript -nologo -e:jscript "%~f0"
- pause&exit
- */
-
- function FormatSize(val){
- var s = '', val = Number(val);
- if(val >= 1125899906842624)
- s = parseInt((val/1125899906842624)*100)/100 +' PB';
- else if(val >= 1099511627776)
- s = parseInt((val/1099511627776)*100)/100 +' TB';
- else if (val >= 1073741824)
- s = parseInt((val/1073741824)*100)/100 +' GB';
- else if (val >= 1048576)
- s = parseInt((val/1048576)*100)/100 +' MB';
- else if (val >= 1024)
- s = parseInt((val/1024)*100)/100 +' KB';
- else s = val+' 字节';
- return s;
- }
-
- var files = WSH.StdIn.ReadAll().split(/\r\n/);
- var count = {}, size = {};
- for(var i = 0; i<files.length; i++){
- var f = files[i].split('*');
- var ext = /\./.test(f[0])?f[0].replace(/.+(\.[^\.]+)/, '$1'):f[0];
- var ext = ext.toLowerCase();
- count[ext]?count[ext]++:count[ext]=1;
- size[ext]?size[ext]+=Number(f[1]):size[ext]=Number(f[1]);
- }
-
- var n = m = sum =0, txt = '';
- for (var e in count){
- /\./.test(e)?n++:m++;
- sum+=size[e];
- txt +=e +'\t'+ count[e] +'\t'+ FormatSize(size[e]) +'\r\n';
- }
- var txt = txt+ '共' +n+ '种类型,';
- if(m>0)txt += m +'个无扩展名的文件,';
- WSH.echo(txt +'总大小'+ FormatSize(sum));
复制代码
|