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

Re: Problem while sorting with Recordset by Walter

Walter
Thu Oct 23 00:00:17 CDT 2003

The maximum field size for adInteger is 2^32 -1, or 4,294,967,295. A 5 gb
folder size overflows the field's capabilities, so you should use a larger
field size.

"jnirmal" <member33076@dbforums.com> wrote in message
news:3512461.1066859279@dbforums.com...
|
| 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



Re: Problem while sorting with Recordset by jnirmal

jnirmal
Thu Oct 23 06:38:04 CDT 2003


Thanks for the response.



I did try adBigInt (8-byte signed) instead of adInteger (4-byte signed)
and also 'unsigned', 'floating point' etc, etc, ...but to no avil.
Obviously, I'm not very good with field types. The way I tried was as
below. Is there something I'm doing wrong?



Const adBigInt = 20

Const adVarChar = 200

Const MaxCharacters = 255

Set DataList = CreateObject("ADODB.Recordset")

DataList.Fields.Append "FName", adVarChar, MaxCharacters

DataList.Fields.Append "FSize", adBigInt

DataList.Open


--
Posted via http://dbforums.com