getfilenames的问题求助!
现在能够实现单个文件路径和文件名的提取,实现方法如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
Dim path As String = OpenFileDialog1.FileName
ListBox1.Items.Add(System.IO.Path.GetFullPath(path))
ListBox2.Items.Add(System.IO.Path.GetFileNameWithoutExtension(path))
End Sub
可是如果我要想用在openfiledialog中选择多个文件后,如何在listbox1和listbox2中分别显示这多个文件的路径和文件名呢?
请予以帮助,多谢!
[解决办法]
OpenFileDialog1.Multiselect = True
OpenFileDialog1.Filter = "所有文件(*.*)|*.* "
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim i As Int32 = OpenFileDialog1.FileNames.Length
Dim path() As String = OpenFileDialog1.FileNames //定义string数组
Dim x As Int32 = 0
For x = 0 To i - 1 //循环遍历
path(x) = OpenFileDialog1.FileNames(x) //获取文件名
ListBox1.Items.Add(path(x)) //加到listbox
ListBox2.Items.Add(path(x).Substring(path(x).LastIndexOf( "\ "))) //取子字节
Next
End If