前端之家收集整理的这篇文章主要介绍了
[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 List
Box1.Items.Add(System.IO.Path.GetFullPath(path)) List
Box2.Items.Add(System.IO.Path.GetFileNameWithoutExtension(path)) End Sub 可是如果我要想用在openfiledialog中选择多个
文件后,如何在list
Box1和list
Box2中分别
显示这多个
文件的路径和
文件名呢? 请予以帮助,多谢! __________________________________________________________________________ if (openFileDialog1.ShowDialog() == DialogResult.OK) { String[] files = openFileDialog1.FileNames; foreach (string str in files) { List
Box1.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) //
获取文件名 List
Box1.Items.Add(path(x)) //加到list
Box List
Box2.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