any function for listing out all the files of a specified type in a folder in VB6

前端 未结 6 1689
无人及你
无人及你 2020-12-04 03:36

I would like to know if there are some in built functions for the scenario that is described below :

The input is the path of a parent folder. Wat the function must

6条回答
  •  囚心锁ツ
    2020-12-04 03:57

    For VB6.0 I would make use of the FileSystemObject and a small recursive function.

    Sub test()
      Dim fso As New Scripting.FileSystemObject
      Dim files As New Collection
      Dim file As Scripting.file
    
      GetFilesRecursive fso.GetFolder("C:\YourFolder"), "zip", files, fso
    
      For Each file In files
        Debug.Print file.Name
      Next file
    End Sub
    
    Sub GetFilesRecursive(f As Scripting.Folder, filter As String, c As Collection, fso As Scripting.FileSystemObject)
      Dim sf As Scripting.Folder
      Dim file As Scripting.file
    
      For Each file In f.Files
        If InStr(1, fso.GetExtensionName(file.Name), filter, vbTextCompare) = 1 Then
          c.Add file, file.path
        End If
      Next file
    
      For Each sf In f.SubFolders
        GetFilesRecursive sf, filter, c, fso
      Next sf
    End Sub
    

    This will not be lightning fast, though. Maximum performance can only be gained by directly using Win32 API functions like FindFirstFile and FindNextFile.

提交回复
热议问题