-1

使用 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
4

3 回答 3

0

System.IO有很多使用 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
于 2013-02-13T12:14:01.907 回答
0

或者

Imports System.IO
...
For Each filePathAsString In Directory.EnumerateFiles("DirPath")
   Label1.Text = filePathAsString
Next
于 2013-02-13T14:14:49.990 回答
0

您可以通过以下方式获取目录的文件名列表:

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

Label然后以你想要的方式添加它:

For Each s As String in sFiles
    Label1.Text &= s & "/"
Next
于 2013-02-13T12:09:53.607 回答