求,求,求,急急急,啊.......如何将一个文件夹下的文件及子文件夹下的文件名称一并取到添加到LISTBOX中.

cxy_999 2004-10-29 04:19:20
从一个文件夹中取文件名,如果在此文件夹中还有子文件夹,那么这个子文件夹中的文件名也要取出,如果这其中还有子文件夹,那么还取,这样,取尽为止.求解.
...全文
94 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
oo渣渣oo 2004-10-29
  • 打赏
  • 举报
回复
Tools.UniteStrArrayA(strSubFile, strSubSubFile)是将第二个参数中的数据合并到第一个参数中,这个你自己写吧
oo渣渣oo 2004-10-29
  • 打赏
  • 举报
回复
算了,把我的给你吧.下面的函数可以正常运行,我正用着呢

'获取指定目录下的所有文件名(包括子目录)(使用了递归调用)
Private Function DynamicList(ByVal strParentDir As String) As String()
Dim strSubDir() As String
Dim strSubFile() As String
Dim strSubSubFile() As String
If Tools.IsFileExist(strParentDir) Then
ReDim strSubFile(0)
strSubFile(0) = strParentDir
Else
Dim objDir As Directory
Dim I As Integer = 0
Try
strSubDir = objDir.GetDirectories(strParentDir)
strSubFile = objDir.GetFiles(strParentDir)
If Not IsNothing(strSubDir) Then
For I = 0 To strSubDir.Length - 1
strSubSubFile = DynamicList(strSubDir(I))
If Not IsNothing(strSubSubFile) Then Tools.UniteStrArrayA(strSubFile, strSubSubFile)
Next
End If
Catch e As Exception
AddSysLog("取要备份的文件列表时发生错误:" & e.Message & "(" & strParentDir & ")", EventLogEntryType.Error, 101)
strSubFile = Nothing
Finally
strSubDir = Nothing
strSubSubFile = Nothing
objDir = Nothing
End Try
End If
Return strSubFile
End Function
oo渣渣oo 2004-10-29
  • 打赏
  • 举报
回复
有递归函数啊,很简单的

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧