本帖最后由 CrLf 于 2018-7-11 12:39 编辑
正好用到,用 bat+js 重写了一个- 1>1/* :
- @cscript /nologo /e:jscript "%~f0" %*
- @exit /b
- */
-
- var arg = WScript.Arguments
-
-
-
- var option = {
- SubFolders: arg.Named.Exists("s"),
- Help: arg.Named.Exists("?")
- }
-
- if(option.Help){
- WSH.Echo(
- 'getFoldersSize 批量获取文件夹大小 v1.1 by http://bbs.bathome.net CrLf\r\n'
- + '\r\n'
- + 'Usage: getFoldersSize [Path] [/S]\r\n'
- + '\r\n'
- + ' Path 目标文件夹路径或目录名,目录名可包含通配符\r\n'
- + '\r\n'
- + ' /S 遍历子目录\r\n'
- )
-
- WSH.Quit()
- }
-
-
- var strPath = "."
- var rePattern = new RegExp()
-
- if(arg.Unnamed.Count){
- var strFoler = arg.Unnamed(0)
-
- strPath = strFoler.replace(/[^\\\/:]+$/,'') || '.'
-
- rePattern.compile(
- '^'
- +strFoler
- .replace(/.*[\\\/:\|"'\<\>]/g,'')
- .replace(/\W/g,'\\$&')
- .replace(/\\\*/g,'.*')
- .replace(/\\\?/g,'.')
- +'$'
- ,'im'
- )
- }
-
- getFolderSize(strPath, rePattern, option)
-
-
-
- function getFolderSize(strPath, rePattern, option){
-
- var fso = WScript.CreateObject("Scripting.Filesystemobject")
-
- var objFolder = fso.GetFolder(strPath);
- var objSubFolders = new Enumerator(objFolder.SubFolders);
-
- for (; !objSubFolders.atEnd(); objSubFolders.moveNext()) {
- var fc = objSubFolders.item()
- try{
- if(fc.Name.search(rePattern)>-1){
- var size = (' '+fc.Size).replace(/.*(.{12})$/,'$1')
- var name = option.SubFolders ? fc.Path + '\\' + fc.Name : fc.Name
- WSH.Echo(size+' '+name);
- }
- if(option.SubFolders)getSubFolderSize(fc, rePattern, option)
- }
- catch(E){
- WSH.StdErr.WriteLine('Error:'+E.message+' - '+fc.Name);
- }
- }
- }
-
- function getSubFolderSize(objFolder, rePattern, option){
- var objSubFolders = new Enumerator(objFolder.SubFolders);
- var arrEcho = []
- for (; !objSubFolders.atEnd(); objSubFolders.moveNext()) {
- var fc = objSubFolders.item()
- try{
- if(fc.Name.search(rePattern)>-1){
- var size = (' '+fc.Size).replace(/.*(.{12})$/,'$1')
- var name = fc.Path + '\\' + fc.Name
- WSH.Echo(size+' '+name);
- }
- }
- catch(E){
- WSH.StdErr.WriteLine('Error:'+E.message+' - '+fc.Name);
- }
-
- getSubFolderSize(fc, rePattern, option)
- }
- }
复制代码
|