从目录VB.NET中的文件夹和子文件夹中获取所有列表框文件的替代方法 [英] Alternative way to get all list box files from folders and sub folders ect in directory VB.NET
本文介绍了从目录VB.NET中的文件夹和子文件夹中获取所有列表框文件的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前的方式我已经运行良好它有时不起作用是否有另一种方式到下面的方法或改进方法:
Sub scanSubfolders(ByVal FolderLocation As String,ByVal lstbox As ListBox)
每个人在My.Computer.FileSystem.GetFiles(FolderLocation)
尝试
lstbox.Items.Add(s)
Catch ex As Exception
结束尝试
下一个
每个s在My.Computer.FileSystem.GetDirectories(FolderLocation)
尝试
scanSubfolders(s,ListBox1)
Catch ex As Exception
结束尝试
下一个
结束子
欢呼
oh和表格加载
scanSubfolders(My.Computer.FileSystem.SpecialDirectories.Temp,Me.ListBox1)
我尝试了什么:
i上面写了我试过的等希望有人可以帮助。
解决方案
哦,你走了:
Imports System.IO
私有 Sub scanFolders(< span class =code-keyword> ByVal FolderLocation As String )
尝试
对于 每个 d 在 Directory.GetDirectories(FolderLocation)
ListBox1.Items.Add(d)
For 每个 f 在 Directory.GetFiles(d, *。*)
ListBox1.Items.Add(f)
Next
scanFol ders(d)
下一步
Catch ex 作为例外
' 日志错误
结束 尝试
结束 子跨度>
the current way Ive got inst working well it sometimes doesn't work is there another way to the one below or a way to improve :
Sub scanSubfolders(ByVal FolderLocation As String, ByVal lstbox As ListBox) For Each s In My.Computer.FileSystem.GetFiles(FolderLocation) Try lstbox.Items.Add(s) Catch ex As Exception End Try Next For Each s In My.Computer.FileSystem.GetDirectories(FolderLocation) Try scanSubfolders(s, ListBox1) Catch ex As Exception End Try Next End Sub
cheers
oh and form load
scanSubfolders(My.Computer.FileSystem.SpecialDirectories.Temp, Me.ListBox1)
What I have tried:
i wrote above what ive tried ect so hope someone could help.
解决方案
Oh, here you go:
Imports System.IO Private Sub scanFolders(ByVal FolderLocation As String) Try For Each d In Directory.GetDirectories(FolderLocation) ListBox1.Items.Add(d) For Each f In Directory.GetFiles(d, "*.*") ListBox1.Items.Add(f) Next scanFolders(d) Next Catch ex As Exception ' log error End Try End Sub
这篇关于从目录VB.NET中的文件夹和子文件夹中获取所有列表框文件的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文