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.
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.