检索目录中所有文件(包括子文件夹)的最快方法是什么。目前我正在使用此功能:
Public Function FindFiles(path As String, Recursive As Boolean) As Boolean
Dim dirInfo As New IO.DirectoryInfo(path)
Dim fileObject As FileSystemInfo
If Recursive = True Then
For Each fileObject In dirInfo.GetFileSystemInfos()
If System.IO.Directory.Exists(fileObject.FullName) Then
FindFiles(fileObject.FullName, Recursive)
Else
'fileObject.FullName - found file
End If
Next
Else
For Each fileObject In dirInfo.GetFileSystemInfos()
If Not System.IO.Directory.Exists(fileObject.FullName) Then
'fileObject.FullName - found file
End If
Next
End If
End Function
由于
答案 0 :(得分:0)
试试这个
Private Function getAllFolders(ByVal directory As String) As String()
Dim fi As New IO.DirectoryInfo(directory) 'Create object
Dim path() As String = {} 'Array to store paths
'Loop through subfolders
For Each subfolder As IO.DirectoryInfo In fi.GetDirectories()
Array.Resize(path, path.Length + 1) 'Add this folders name
path(path.Length - 1) = subfolder.FullName
'Recall function with each subdirectory
For Each s As String In getAllFolders(subfolder.FullName)
Array.Resize(path, path.Length + 1)
path(path.Length - 1) = s
Next
Next
Return path
End Function