2013-02-13 87 views
-1

使用vb.net,我该如何遍历给定目录中的所有文件名,然后将它们显示在标签中?标签vb.net中的循环文件名

Dim PATH_DIR_1 As String 
Dim INTERVAL_DIR_1 As String 

PATH_DIR_1 = Registry.GetValue("HKEY_CLASSES_ROOT\SOFTWARE\Sidewinder", "DIR_1", "") 

INTERVAL_DIR_1 = Registry.GetValue("HKEY_CLASSES_ROOT\SOFTWARE\Sidewinder", "INT_DIR_1", "") 

For Each foundFile As String In (PATH_DIR_1) 
    Label1.Text = (foundFile) 
Next 
+0

你说你要通过文件名环路,但你的代码显示了注册表路径。你要哪个? – aphoria 2013-02-13 14:22:03

回答

0

你可以得到一个目录的文件名列表:

For Each s As String in sFiles 
    Label1.Text &= s & "/" 
Next 
0

System.IO有很多:

Dim sFiles() as String = System.IO.Directory.GetFiles(sDirectoryPath) 

然后在你所希望的方式将其添加在Label用于处理windows文件系统的类,下面是您想要执行的示例:

Imports System.IO 

...... 

Sub DisplayFileList(ByRef theLabel As Label, ByVal thePath As String) 

    Dim di As New DirectoryInfo(thePath) 

    For Each fi As FileInfo In di.GetFiles() 

     theLabel.Text &= fi.FullName 'or just fi.Name, FullName is the complete path 

    Next 

End Sub 
0

或者

Imports System.IO 
... 
For Each filePathAsString In Directory.EnumerateFiles("DirPath") 
    Label1.Text = filePathAsString 
Next