使用 VBScript 排序文件(字母数字)

Sorting Files(alphanumerical) using VBScript

我有一个文件夹,其中包含以下格式的文件: File_1、File_2...File_n

当我遍历它们时,这是我收到的输出:

File_1,File_10,File_11...

如何使用 VBScript 对文件进行排序,以便收到所需的输出(File_1、File_2...)?

下面是我到目前为止开发的代码:

Set objFSO = CreateObject("Scripting.FileSystemObject")
  objStartFolder = "FilePath"

  Set objFolder = objFSO.GetFolder(objStartFolder)
  Set colFiles = objFolder.Files
  For Each objFile in colFiles
  
    File = File & "," & objFile.Name
Next
 MsgBox File

这是我编写的一个子例程,它将 return 排序数组。

你会像这样使用它:

oSortedFile = ArraySort(objFile, "desc")


Sub ArraySort(aArrayToSort, sOrder)
  'This script is provided under the Creative Commons license located
  'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
  'be used for commercial purposes with out the expressed written consent
  'of NateRice.com
  'This Sub will sort the array passed as aArrayToSort
  For i = UBound(aArrayToSort) - 1 To 0 Step -1
    For j = 0 To i
      If aArrayToSort(j) < aArrayToSort(j+1) And sOrder = "desc" Then
        sTempStr = aArrayToSort(j+1)
        aArrayToSort(j+1) = aArrayToSort(j)
        aArrayToSort(j) = sTempStr
      ElseIf aArrayToSort(j) > aArrayToSort(j+1) And sOrder = "asc" Then
        sTempStr = aArrayToSort(j+1)
        aArrayToSort(j+1) = aArrayToSort(j)
        aArrayToSort(j) = sTempStr
      End If
    Next
  Next
End Sub