本帖最后由 terse 于 2015-6-5 18:00 编辑
文件名排序的 你这样试试
dir /on 文件名 /os 是按大小 竟然错了 改下- @if(0)==(0) echo off & dir /b /s /on/a-d | CScript -NoLogo -E:JScript %0 >文件名_大小.txt & pause & exit @end
-
- var fso=new ActiveXObject("Scripting.FileSystemObject");
- var k=1024, m=1048576, g=1073741824;
-
- while (!WScript.StdIn.AtEndOfStream){
- var name = WScript.StdIn.ReadLine();
- var f =fso.GetFile(name)
- WSH.Echo(f.name,filesize(f.size))
- };
-
- function filesize(size) {
- switch(true){
- case size>g :
- size = (size/g).toFixed(2) + ' GB';
- break;
- case size>m :
- size = (size/m).toFixed(2) + ' MB';
- break;
- case size>k :
- size = (size/k).toFixed(2) + ' KB';
- break;
- default :
- size = size + ' 字节';
- };
- return size;
- }
复制代码 下面是文件大小排序- @if(0)==(0) echo off & CScript -NoLogo -E:JScript %0 >文件名_大小.txt & pause & exit @end
- var fso=new ActiveXObject("Scripting.FileSystemObject");
- var Folder = fso.GetFolder(WScript.Arguments.Count()?WScript.Arguments.Item(0):".");
- var arr=[], i=0, k=1024, m=1048576, g=1073741824;
- for(var e = new Enumerator(Folder.Files);!e.atEnd();e.moveNext()){
- var f = e.item();
- arr.push([f.Name, f.Size]);
- }
- arr = arr.sort(function(a,b){ return a[1] - b[1]});
- for (i = 0,len = arr.length; i < len; i++) {
- var size = arr[i][1];
- switch(true){
- case size<k :
- WSH.Echo(arr[i][0],'\t' + size,' Byte');
- break;
- case size<m :
- WSH.Echo(arr[i][0],'\t' + (size/k).toFixed(2),' KB');
- break;
- case size<g :
- WSH.Echo(arr[i][0],'\t' + (size/m).toFixed(2),' MB');
- break;
- default :
- WSH.Echo(arr[i][0],'\t' + (size/g).toFixed(2),' GB');
- }
- }
复制代码
|