...

View Full Version : How to sort with FSO?



angst
03-03-2006, 07:54 PM
Hello,
I'm wondering how I can order a list of folders with File System Object,
but a little more then that,

I've got a list of folders that have user id numbers for names, so I've build a simpler data base function to show the name of the user insted of the number. I *think* what I need to do it load it up into an array, and sort it from there, but I've never trying sorting an array.

any ideas?

thanks in advance for your time!
-Ken

angst
03-03-2006, 08:28 PM
ok!
I found this script:

http://www.4guysfromrolla.com/demos/2dsort.asp

which works fine.
but I'm not exactly sure how to load all my data into a 2 dimensional array.

any ideas?

thanks in advance for your time!
-Ken

angst
03-03-2006, 08:44 PM
ah, and there we go:-)

incase anyone needs this, here it is:



<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder(Server.MapPath("/admin/orders/artwork/"))

Dim arrDualArray()
Dim subFolders
Set subFolders = rootFolder.SubFolders
numFolders = subFolders.Count
ReDim arrDualArray(numFolders, 2)

' gather data into array
numArrayIndex = 0
For Each folder in subFolders
arrDualArray( numArrayIndex, 0 ) = GetClientNameByID( folder.Name )
arrDualArray( numArrayIndex, 1 ) = folder.Name
numArrayIndex = numArrayIndex + 1
Next

' start sort
Sub DualSorter( byRef arrArray, DimensionToSort )
Dim row, j, StartingKeyValue, StartingOtherValue, _
NewStartingKey, NewStartingOther, _
swap_pos, OtherDimension
Const column = 1

' Ensure that the user has picked a valid DimensionToSort
If DimensionToSort = 1 then
OtherDimension = 0
ElseIf DimensionToSort = 0 then
OtherDimension = 1
Else
'Shoot, invalid value of DimensionToSort
Response.Write "Invalid dimension for DimensionToSort: " & _
"must be value of 1 or 0."
Response.End
End If

For row = 0 To UBound( arrArray, column ) - 1

StartingKeyValue = arrArray ( row, DimensionToSort )
StartingOtherValue = arrArray ( row, OtherDimension )

NewStartingKey = arrArray ( row, DimensionToSort )
NewStartingOther = arrArray ( row, OtherDimension )

swap_pos = row

For j = row + 1 to UBound( arrArray, column )
If arrArray ( j, DimensionToSort ) < NewStartingKey Then
swap_pos = j
NewStartingKey = arrArray ( j, DimensionToSort )
NewStartingOther = arrArray ( j, OtherDimension )
End If
Next

If swap_pos <> row Then
arrArray ( swap_pos, DimensionToSort ) = StartingKeyValue
arrArray ( swap_pos, OtherDimension ) = StartingOtherValue

arrArray ( row, DimensionToSort ) = NewStartingKey
arrArray ( row, OtherDimension ) = NewStartingOther

End If
Next
End Sub


call DualSorter(arrDualArray, 0)

For i = LBound(arrDualArray) to UBound(arrDualArray)
Response.Write arrDualArray(i, 0) & " - "
Response.Write arrDualArray(i, 1) & "<BR>"
Next
%>


-Ken

BarrMan
03-05-2006, 03:52 PM
For what do i need FSO?

angst
03-05-2006, 04:15 PM
http://www.tutorial-web.com/asp/fso/



The FileSystem Object is the object that is used to manipulate the filesystem in Active Server Pages. Moving files, opening and reading text files, and looking at drive space are a few of the many functions of the FileSystem Object. The FileSystem Object actually contains five objects: the main Filesystem object, the Drive object, the Folder object, the File object, and the TextStream object.

Bullschmidt
03-07-2006, 02:13 AM
And here's a great FSO resource:

Could I get some help working with files using FileSystemObject?
http://www.aspfaq.com/show.asp?id=2039



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum