[VB.NET]getfilenames的问题求助!
发布时间:2020-12-16 23:48:10 所属栏目:大数据 来源:网络整理
导读:getfilenames的问题求助! 现在能够实现单个文件路径和文件名的提取,实现方法如下: Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.ShowDialog() Dim path As String = Op
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 __________________________________________________________________________ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |