Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ordering of files in folder object 1

Status
Not open for further replies.

Microbe

Programmer
Oct 16, 2000
607
AU
Hey all,

Have done a dump of files in a folder using:

set fileSYS=server.createObject("scripting.FileSystemObject")
set folderName = fileSYS.GetFolder("c:\pathtofolder")
set allFiles = folderName.files

for each file in allFiles
response.write file.name & &quot;<br>&quot;
next

the output is:

1-1-template.asp
1-2-template.asp
1-10-template.asp
1-9-template.asp
1-8-template.asp
1-4-template.asp
1-5-template.asp
1-6-template.asp
1-7-template.asp
1-3-template.asp

Which is perfect EXCEPT for the ordering.

They were created in numerical (1-1 then 1-2 etc) order, so how does the array determine in what order to suck them in?
Steve Davis
hey.you@hahaha.com.au
 
I believe it takes them in the order that they it encounters them. To do it ny other way without a user specified property or method would be a waste of resources. I suppose the real question is how do they get in that order in the directory? Hashing maybe?
 
Hmmm...this is on Win2k at the moment but server is Linux.

Did a DIR and they pop up in the same order as above, so I guess that is the order they are in the FAT.

Never done sorting in an array...even on output would be fine...anyone?
Steve Davis
hey.you@hahaha.com.au
 
I think the DIR does a sort.
Code:
Public Function SortStrComp(aryS() As String, Optional ByVal lngCompareType As CompareMethod) As Long()
    ' Sort the Array
' Return an array of indexes into string array such that
' indexes return elements in sequence.
' aryS() - array of strings to be sorted
' lngCompareMethod - see StrComp
' Returns array of Longs which are indexes to strings.
'         array of strings is NOT rearranged.
' For I = 0 to Ubound(aryLngs)
'     Debug.Print aryS(aryLngs(I))
' Next
    Dim lngN        As Long, _
        lngGAP      As Long, _
        I           As Long, _
        J           As Long, _
        JGap        As Long, _
        lngI        As Long, _
        lngIGap     As Long, _
        lngBound    As Long
    Dim lngSwap     As Long
    Dim aryI()      As Long
       
    lngBound = UBound(aryS)
        
    lngN = UBound(aryS) + 1 ' Get Actual Count including 0
    ReDim aryI(lngBound) As Long
    
    For I = 0 To lngN - 1
        aryI(I) = I
    Next
    
    lngGAP = 1
    Do While (lngGAP < lngN)
        lngGAP = lngGAP * 3 + 1
    Loop
    lngGAP = (lngGAP - 1) \ 3
    
    Do While lngGAP > 0
        For I = lngGAP To lngN - 1
            JGap = I
            J = JGap - lngGAP
            Do While J >= 0
                lngI = aryI(J)
                lngIGap = aryI(JGap)
                                
                Select Case StrComp(aryS(lngI), aryS(lngIGap), lngCompareType)
                Case -1
                    Exit Do
                Case 0
                    If lngI <= lngIGap Then
                            Exit Do
                        End If
                End Select
                                
                aryI(J) = lngIGap
                aryI(JGap) = lngI
                
                JGap = J
                J = J - lngGAP
            Loop
        Next
        If lngGAP <= 1 Then Exit Do
        lngGAP = (lngGAP - 1) \ 3
    Loop
    
    SortStrComp = aryI
    
    Erase aryI
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top