0

I am working in a software company. I've used batch file to get the folder size using dir and du but it took 1 sec in dir and 600 msec in du to calculate folder size of 5GB. But I want it to be even faster for the product. So is there any command or tool with command line support which can perform the task faster? Command can be of any type (bat, vbs, powershell....)

Thank you in advance....

IT researcher
  • 3,274
  • 17
  • 79
  • 143

1 Answers1

3

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
Kirill Pashkov
  • 3,118
  • 1
  • 15
  • 20
  • Is there any way to implement it on windows xp, because we have 30% of our client run on windows xp. Can we embed this code in any other scripts, if yes how? Or is there any similar operations in other scripting. – IT researcher Jul 21 '15 at 09:59
  • Sure! You can easily perform these Powershell scripts on Windows XP, assuming you have powershell installed. Just run this with Invoke-Command cmdlet or via GPO logon script. – Kirill Pashkov Jul 21 '15 at 13:01
  • It's difficult to tell the clients to install Powershell. Never mind got the suitable solution in vbs by referring your second command by using .GetFolder and .size Thank you for your help... – IT researcher Jul 21 '15 at 13:16