VB6如何检查子文件夹是否存在
我几十年来一直在寻找这个,但没有成功。 我需要查明我指定的名称的子文件夹是否存在。
For i = 0 To 3 'got 4 different loc to check sub folders
Set f = fso.GetFolder(backupdir(i))
Set sf = f.SubFolders
For Each fr In sf 'for each folder in sub folder
Do Until fr = "" Or fr = Null
If fso.FolderExists(fr.SubFolders) Then
'if more sub folders exist i wanna make sure
'that i can get their subfolders too
'till there is no sub folder left..
sf = fr
End If
Loop
Next fr
Next i
Ive been searching for this for like decades with no success.
I need to find out if a subdfolder that i ve given the name is exist..
For i = 0 To 3 'got 4 different loc to check sub folders
Set f = fso.GetFolder(backupdir(i))
Set sf = f.SubFolders
For Each fr In sf 'for each folder in sub folder
Do Until fr = "" Or fr = Null
If fso.FolderExists(fr.SubFolders) Then
'if more sub folders exist i wanna make sure
'that i can get their subfolders too
'till there is no sub folder left..
sf = fr
End If
Loop
Next fr
Next i
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
诸如遍历文件夹的文件夹中的文件夹之类的操作称为递归。
FindFirstFile:使用文件夹掩码递归搜索文件夹(最少代码)示例 此处展示了如何使用 Windows API 快速完成此操作。
Actions like traversing the folders-of-a-folder-of-a-folder... is called recursing.
The FindFirstFile: Recursive Search for Folders Using a Folder Mask (minimal code) example here shows how to do this quickly with the windows API.
检查此代码。
此代码获取指定目录(本例中为 c:\folderToSearch)中的所有子文件夹,并将它们写入带有“|”的字符串FolderList 中。分隔符。
您还可以使用数组而不是用“|”分隔文件夹名称。
或者您可以在
Form_Load
中的Debug.Print FolderList
行后添加以下代码来获取数组:Check this code.
This code gets all the subfolders in the specified directory(c:\folderToSearch in this case) and writes them into the string FolderList with a "|" seperator.
You can also use an array instead of separating folder names with a "|".
Or you can add the code below after the
Debug.Print FolderList
line inForm_Load
to get an array:您可以使用集合和标准
Dir
函数在 20 行代码中“递归”子文件夹,如下所示You can "recurse" subfolders with a collection and standard
Dir
function in 20 lines of code like this您可以使用 WMI。你可以在CIM_Directory中搜索,我相信字段名称是“name”,
如果它包含您要查找的文件夹或部分文件夹名称,请返回全名。
You could use WMI. You could search in CIM_Directory, I believe the field name is "name",
and if it contains the folder or partially the foldername you are looking for, return the full name.