2个回答
展开全部
用字符数组全部读入排序,后在读取。
或者在读入的时候让操作系统排好顺序再读入。
’将符合条件的条件和目录分类,存到对应的数组中,完成输出
Public Sub main()
Dim FileNames As String, DirNames As String
Dim FileArray() As String, DirArray() As String
Dim TotalDirs As Integer, TotalFiles As Integer
Dim iLoop As Integer
DirNames = "c:\"
FileNames = Dir(Dirname, vbNormal + vbDirectory)
Do While FileNames <> ""
If FileNames <> "." And FileNames <> ".." Then
If (GetAttr(Dirname & FileNames) And vbDirectory) = vbDirectory Then
TotalDirs = TotalDirs + 1
ReDim Preserve DirArray(TotalDirs)
DirArray(TotalDirs) = FileNames
Else
TotalFiles = TotalFiles + 1
ReDim Preserve FileArray(TotalFiles)
FileArray(TotalFiles) = FileNames
End If
End If
FileNames = Dir
Loop
’这里可对数组进行排序,此处略
Debug.Print "___Directories______"
For iLoop = 0 To UBound(DirArray)
Debug.Print DirArray(iLoop)
Next
Debug.Print "___Files____"
For iLoop = 0 To UBound(FileArray)
Debug.Print FileArray(iLoop)
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询