获得“MB”目录的大小使用批处理文件 [英] Get size of a directory in 'MB' using batch file

查看:115
本文介绍了获得“MB”目录的大小使用批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得目录说 C的大小:使用批处理文件的\\ Temp MB 。我不需要孩子目录或文件的大小,但目录本身的大小。

I want to get the size of directory say C:\Temp in MB using batch file. I don't need sizes of child directories or files, but the size of directory itself.

我找到了答案在<一个href=\"http://stackoverflow.com/questions/21711180/how-to-list-all-folder-with-size-via-batch-file/21712766#21712766\">How通过批处理文件列出大小为所有的文件夹

I found an answer at How to list all folder with size via batch file

但它给了我大小的字节和子文件夹。所以我的问题是:

but it gives me size in bytes and that of sub folders. So my question is :

如何获得目录本身的大小 MB

How to get the size of directory itself in MB ?

推荐答案

您可以用混合脚本做的 [批量/ VBScript中] 像这样的:

You can do it with a hybrid script [Batch/Vbscript] like this one :

@echo off
set Folder="C:\temp"
echo The size of %Folder% is 
Call :GetSize %Folder%
pause
:GetSize
(
echo wscript.echo GetSize("%~1"^)
echo Function GetSize(MyFolder^)
echo    Set fso = CreateObject("Scripting.FileSystemObject"^)
echo    Set objFolder= fso.GetFolder(MyFolder^)  
echo    GetSize = FormatSize(objFolder.Size^)
echo End Function
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo    aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo    For i = 0 to 4
echo        If iSize ^> 1024 Then
echo            iSize = iSize / 1024
echo        Else
echo            Exit For
echo        End If
echo    Next
echo    FormatSize = Round(iSize,2^) ^& " " ^& aLabel(i^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b

编辑:于30/03/2016 @ 12:11

Edit : on 30/03/2016 @12:11

和这一个很好的伎俩

在利维乌的黑客用于批量嵌入VBS code,无临时文件

the Liviu's hack for embedding vbscode in batch without temp files

我刚刚发现的 npocmaka 感谢他

I just discovered from npocmaka thanks to him

@echo off
Set Folder="c:\temp"
@cScript.EXE //noLogo "%~f0?.WSF" %Folder%  //job:info %~nx0%*
pause
@exit /b 0
<job id="info">
<script language="VBScript">
wscript.echo GetSize(WScript.Arguments(0))
Function GetSize(MyFolder)
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objFolder= fso.GetFolder(MyFolder)  
    GetSize = FormatSize(objFolder.Size)
End Function
'*******************************************************************
'Function to format a number into typical size scales
Function FormatSize(iSize)
   aLabel = Array("bytes", "KB", "MB", "GB", "TB")
   For i = 0 to 4
        If iSize > 1024 Then
            iSize = iSize / 1024
        Else
            Exit For
        End If
   Next
   FormatSize = Round(iSize,2) & " " & aLabel(i)
End Function
'*******************************************************************
</script>
</job>

这篇关于获得“MB”目录的大小使用批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆