使用vb.net,我如何循环浏览给定目录中的所有文件名,然后在标签中显示它们?
Dim PATH_DIR_1 As String
Dim INTERVAL_DIR_1 As String
PATH_DIR_1 = Registry.GetValue("HKEY_CLASSES_ROOTSOFTWARESidewinder", "DIR_1", "")
INTERVAL_DIR_1 = Registry.GetValue("HKEY_CLASSES_ROOTSOFTWARESidewinder", "INT_DIR_1", "")
For Each foundFile As String In (PATH_DIR_1)
Label1.Text = (foundFile)
Next
您可以使用获取目录的文件名列表
Dim sFiles() as String = System.IO.Directory.GetFiles(sDirectoryPath)
然后以您想要的方式将其添加到Label
中:
For Each s As String in sFiles
Label1.Text &= s & "/"
Next
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
或
Imports System.IO
...
For Each filePathAsString In Directory.EnumerateFiles("DirPath")
Label1.Text = filePathAsString
Next