[VB.NET]getfilenames的问题求助!

前端之家收集整理的这篇文章主要介绍了[VB.NET]getfilenames的问题求助!前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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中分别显示这多个文件的路径和文件名呢? 请予以帮助,多谢! __________________________________________________________________________ if (openFileDialog1.ShowDialog() == DialogResult.OK) { String[] files = openFileDialog1.FileNames; foreach (string str in files) { ListBox1.Items.Add(str); } } __________________________________________________________________________ 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 __________________________________________________________________________ 返回的是string[]遍历就行 __________________________________________________________________________ 感谢大家的热心回复,我用kaozhulanmao的方法实现了,所以分数给了kaozhulanmao,同时感谢ak-47和八戒。 __________________________________________________________________________ 直接用这个软件http://essentialsoft.cn/copyfilenames __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/264034.html

猜你在找的VB相关文章