VB6中用于列出文件夹中指定类型的所有文件的任何函数 [英] 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 :
输入是父文件夹的路径.函数必须做的是,它应该列出该父文件夹中的所有 .zip 文件.父文件夹可以包含任意数量的子文件夹,这同样适用于子文件夹.. 有人可以帮我吗?
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 版本不是路障.VB6 或 VS2005 可以做的任何版本.请帮帮我.如果没有这样的内置功能,还有其他替代方法.提前致谢.
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.
推荐答案
对于 VB6.0,我会使用 FileSystemObject
和一个小的递归函数.
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
不过,这不会很快.只有直接使用 FindFirstFile 和 FindNextFile 等 Win32 API 函数才能获得最大性能.
This will not be lightning fast, though. Maximum performance can only be gained by directly using Win32 API functions like FindFirstFile and FindNextFile.
这篇关于VB6中用于列出文件夹中指定类型的所有文件的任何函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!