Powershell solution.
Read more at https://technet.microsoft.com/en-us/library/ff730945.aspx
$colItems = (Get-ChildItem C:\temp -Recurse | Measure-Object -Property length -Sum)
"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
Measures:
PS C:\> Measure-Command -Expression {
$colItems = (Get-ChildItem C:\temp -Recurse | Measure-Object -Property length -Sum)
"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
}
Days : 0
Hours : 0
Minutes : 0
Seconds : 2
Milliseconds : 509
Ticks : 25092400
TotalDays : 2,90421296296296E-05
TotalHours : 0,000697011111111111
TotalMinutes : 0,0418206666666667
TotalSeconds : 2,50924
TotalMilliseconds : 2509,24
Same with the shell com object:
$objFSO = New-Object -ComObject Scripting.FileSystemObject
"{0:N2}" -f (($objFSO.GetFolder("C:\temp").Size) / 1MB) + " MB"
Measures:
PS C:\> Measure-Command -Expression {
$objFSO = New-Object -ComObject Scripting.FileSystemObject
"{0:N2}" -f (($objFSO.GetFolder("C:\temp").Size) / 1MB) + " MB"
}
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 719
Ticks : 7197995
TotalDays : 8,33101273148148E-06
TotalHours : 0,000199944305555556
TotalMinutes : 0,0119966583333333
TotalSeconds : 0,7197995
TotalMilliseconds : 719,7995