如何使用vb6 ....从子文件夹中获取所有文件列表? [英] How to get all file list from subfolder using vb6....?
本文介绍了如何使用vb6 ....从子文件夹中获取所有文件列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试以下代码从文件夹和子文件夹获取所有文件列表.
I try following code to get all file list from folder and sub folder.
Dim fs As FileSystemObject
Set fs = New FileSystemObject
Dim foldeer As Folder
Dim Filnavn() As String
Set foldeer = fs.GetFolder("C:\Folder1")
For Each Folder In foldeer.SubFolders
For Each File In Folder.Files
Filnavn() = Split(File, "\")
MsgBox Filnavn(UBound(Filnavn()))
Next
Next
For Each File In foldeer.Files
Filnavn() = Split(File, "\")
MsgBox Filnavn(UBound(Filnavn()))
Next
但是此代码无法显示子文件夹中的所有文件,我的意思是,如果我创建任何文件夹和子文件夹,例如"C:\ folder1 \ folder2 \ folder3 \ folder4",则在这种情况下,此代码仅向我显示文件夹1和folder2中的文件,但我还想从folder3和folder4以及四个以上的子文件夹中查找.那么如何找到该文件呢?
But this code cannot show all file in sub folder I mean if I create any folders and sub folders like "C:\folder1\folder2\folder3\folder4" then in this case this code only show me though file that is in folder1 and folder2, but I want to also find from folder3 and folder4 and more than four sub folder. So how to find this file..?
推荐答案
您需要的是递归.创建一个从一个文件夹中提取文件的子或函数,然后在其中为每个文件夹调用相同的子.
这样的东西(伪代码):
What you need is a recursion. Create a sub or function that fetches files from one folder, then in that call the same sub for each folder.
So something like (pseudo code):
sub FolderFiles(foldername as string)
for each file in foldername
add file to list
next
for each subfolder in foldername
FolderFiles(subfolder)
next
end sub
这篇关于如何使用vb6 ....从子文件夹中获取所有文件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文