Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sorting the result of FileSystemObject.Folder.files collection

1,699 views
Skip to first unread message

Etienne Charlier

unread,
Apr 3, 2001, 3:30:41 PM4/3/01
to
Hi,

I would like to process all the files in a folder staring with the biggest.

I didn't found any property that I can use to specify this order to the
Folder.Files collection

I use ( form memory

dim fs as new Filesystemobject
dim fldr as Folder
dim F as File

set flder = fs.GetFolder("c:\.....")
for each f in fldr.files
'process F
' I want the biggest first then the other in desc order
next


????
Etienne....@simens.be


Tom Lavedas

unread,
Apr 3, 2001, 4:08:49 PM4/3/01
to

Quoting from VBScript documentation:

Size Property

For files, returns the size, in bytes, of the specified file. For
folders, returns the size, in bytes, of all files and subfolders
contained in the folder.

object.Size

The object is always a File or Folder object.

Documentation (compiled html download)

http://msdn.microsoft.com/scripting/windowshost/wshdoc.exe
http://msdn.microsoft.com/scripting/vbscript/download/vbsdoc.exe


Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

Steve Fulton

unread,
Apr 3, 2001, 4:56:39 PM4/3/01
to
You could always use a recordset:

Const adVarChar = 200, adBigInt = 20
Set fso = CreateObject("Scripting.FileSystemObject")
Set rsFiles = CreateObject("ADODB.Recordset")
rsFiles.Fields.Append "Path", adVarChar, 255
rsFiles.Fields.Append "Size", adBigInt

rsFiles.Open
For Each F In fso.GetFolder(".").Files ' your path here
rsFiles.AddNew
rsFiles("Path") = F.Path
rsFiles("Size") = F.Size
Next

rsFiles.Sort = "Size DESC"
Do Until rsFiles.EOF
Set F = fso.GetFile(rsFiles("Path"))
' Process F
WScript.Echo F.Name, vbTab, FormatNumber(F.Size, 0, True)
rsFiles.MoveNext
Loop

=-=-=
Steve
-=-=-

"Etienne Charlier" <Etienne....@advalvas.be> wrote in message
news:3aca25e2$0$27807$456d...@news.skynet.be...

Etienne Charlier

unread,
Apr 5, 2001, 2:40:47 PM4/5/01
to
Thanks a lot,
A little bit "Heavy" but I'll try

Etienne
"Steve Fulton" <cerbe...@hotmail.com> wrote in message
news:#n7XbQIvAHA.2160@tkmsftngp02...

Prema

unread,
Apr 10, 2001, 4:31:17 AM4/10/01
to
how about using an array/dictionary to keep track of the different file
sizes in a Files collection.
then run a simple sorting algorithm -such as bubblesort to order the array.
the loop thru the array to get the sorted list by file sizes...
i'll try implementing this....so hang in there :)
laterz, prema


0 new messages