Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
923 views
in Technique[技术] by (71.8m points)

vb.net - any function for listing out all the files of a specified type in a folder in VB6

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 do is , it should list out all the .zip files inside that parent folder.The parent folder can contain any number of subfolders, and the same applies to the subfolders too .. Can anybody help me out with that ?

VB version is not a barricade. Any of the versions VB6 or VS2005 can do. Pls help me out. Also is there any other alternative way if there are no inbuilt functions as such. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...