I use the following script to return folders on remote machines sorted
by size. Most times it works fine, but sometimes the size of the largest
folder (maybe around 5 gb) is returned as 0.
If I list the files sizes without sorting them, the size shows up fine.
So the problem is while sorting.
Does anyone have any idea why this happens? Thanks.
On Error Resume Next
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set sRootDir = oFSO.GetFolder("\\strComputer\c$\")
Const adInteger = 3
Const adVarChar = 200
Const MaxCharacters = 255
Set DataList = CreateObject("ADODB.Recordset")
DataList.Fields.Append "FName", adVarChar, MaxCharacters
DataList.Fields.Append "FSize", adInteger
DataList.Open
Set sSubDirs = sRootDir.SubFolders
For Each sDir In sSubDirs
DataList.AddNew
DataList("FName") = sDir.Path
DataList("FSize") = sDir.Size
DataList.Update
Next
DataList.Sort = "FSize DESC"
DataList.MoveFirst
Do Until DataList.EOF
WScript.Echo ConvBytes(DataList.Fields.Item("FSize")) & vbTAB & vbTAB
& DataList.Fields.Item("FName")
DataList.MoveNext
Loop
Public Function ConvBytes(SizeInBytes)
If isNumeric(SizeInBytes) Then
If Int(SizeInBytes) < 1000 Then
ConvBytes = Round(Int(SizeInBytes),2) & " bytes"
ElseIf Int(SizeInBytes) < 1000000 Then
ConvBytes = Round((Int(SizeInBytes)/1024),2) & " KB"
ElseIf Int(SizeInBytes) < 1000000000 Then
ConvBytes = Round((Int(SizeInBytes)/1048576),2) & " MB"
ElseIf Int(SizeInBytes) < 1000000000000 Then
ConvBytes = Round((Int(SizeInBytes)/1073741824),2) & " GB"
End If
End If
End Function
--
Posted via http://dbforums.com