以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何选择一个文件夹,并遍历该目录下的所有子目录,读取txt文件的内容  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=190889)

--  作者:sloyy
--  发布时间:2024/3/11 22:43:00
--  如何选择一个文件夹,并遍历该目录下的所有子目录,读取txt文件的内容
一个文件夹,下面包含很多子目录,想遍历这个文件夹,读取所有子目录内的txt文件,该怎么做?


--  作者:pyh6918
--  发布时间:2024/3/11 23:02:00
--  
帮助文件搜:FileSys
--  作者:有点蓝
--  发布时间:2024/3/11 23:08:00
--  
参考:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=186470&skin=0
--  作者:sloyy
--  发布时间:2024/3/12 12:52:00
--  
封装成内部函数,拿去用吧
Dim lg As New List(Of String)
Dim dlg As New FolderBrowserDialog
If dlg.ShowDialog = DialogResult.Ok Then
Dim path As String = args(0)
Dim ls = args(1)
For Each file As String In FileSys.GetFiles(path)
    If file.Contains(".txt") Then
        ls.add(file)
    End If
Next
For Each p As String In FileSys.GetDirectories(path) \'循环调用自身代码
    Functions.Execute("文件递归", p, ls)
Next
End If