<%
Dim fso, folder, file, filesArray, i, j, temp
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(filepath) ' filepath是你想要排序文件的文件夹路径
' 将文件集合复制到数组中
ReDim filesArray(folder.Files.Count)
For i = 1 To folder.Files.Count
Set file = folder.Files(i)
filesArray(i-1) = file.Name
Next
' 对数组进行冒泡排序
For i = 0 To UBound(filesArray) - 1
For j = i + 1 To UBound(filesArray)
If filesArray(i) > filesArray(j) Then
temp = filesArray(i)
filesArray(i) = filesArray(j)
filesArray(j) = temp
End If
Next
Next
' 输出排序后的文件名
For i = 0 To UBound(filesArray)
Response.Write filesArray(i) & "<br>"
Next
' 清理
Set folder = Nothing
Set fso = Nothing
%> |