I tried to use the bubble sort function to sort a list of files, but the sort does not work properly. It sorts some files in the folder to a certain point and then it starts all over again.
I finally ended up using the Disconnected Record routine to sort files.
Any ideas why the bubble sort does work?. The sort code I have is listed below:
Dim arrItem, arrSortItem
strFolder = "C:\WINNT"
Set objFSO = CreateObject("Scripting.FileSystemObject")
arrItem = Array(1)
arrSortItem = Array(1)
i = 0
For Each strFile In objFSO.GetFolder(strFolder).Files
arrItem(i) = strFile.Name
i = i + 1
ReDim Preserve arrItem(i)
Next
arrSortItem = SortItem(arrItem)
For i = 0 To ubound(arrSortItem)
strFileName = arrSortItem(i)
Wscript.Echo strFileName
Next
'Function to sort the files
Function SortItem(arrSort)
Dim k, j, temp
For k = UBound(arrSort) - 1 To 0 Step -1
For j= 0 To k
If arrSort(j)>arrSort(j+1) Then
temp=arrSort(j+1)
arrSort(j+1)=arrSort(j)
arrSort(j)=temp
End If
Next
Next
SortItem = arrSort
End Function
Thanks!
I finally ended up using the Disconnected Record routine to sort files.
Any ideas why the bubble sort does work?. The sort code I have is listed below:
Dim arrItem, arrSortItem
strFolder = "C:\WINNT"
Set objFSO = CreateObject("Scripting.FileSystemObject")
arrItem = Array(1)
arrSortItem = Array(1)
i = 0
For Each strFile In objFSO.GetFolder(strFolder).Files
arrItem(i) = strFile.Name
i = i + 1
ReDim Preserve arrItem(i)
Next
arrSortItem = SortItem(arrItem)
For i = 0 To ubound(arrSortItem)
strFileName = arrSortItem(i)
Wscript.Echo strFileName
Next
'Function to sort the files
Function SortItem(arrSort)
Dim k, j, temp
For k = UBound(arrSort) - 1 To 0 Step -1
For j= 0 To k
If arrSort(j)>arrSort(j+1) Then
temp=arrSort(j+1)
arrSort(j+1)=arrSort(j)
arrSort(j)=temp
End If
Next
Next
SortItem = arrSort
End Function
Thanks!