
正文
vb.net选中文件路径 vb选择打开文件路径
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
[VB.NET]当前活动资源管理器窗口某文件夹被选定,请问获取该选定的文件夹的路径?
OpenFileDialog openFile = new OpenFileDialog();
openFile.Multiselect = true;
openFile.Filter = "图片 (*.jpg)|*.jpg|所有文件 (*.*)|*.*";
if (openFile.ShowDialog() == DialogResult.OK)
{
string ss = openFile.FileName;
string ww = openFile.FileName.Remove(openFile.FileName.Length - 4, 4);
File.Copy(ss, @"..\..\picture\" + Path.GetFileName(ss));
}
上面是先获取路径,在把图片复制到指定路径下。
相关问答
Q1: vb.net文件关联后获取文件路径
我没有设置关联vb.net选中文件路径,只是把文件拖到程序文件上打开,应该是一样的。
主要是看程序启动时的命令行参数My.Application.CommandLineArgs,里面包括要打开的文件路径。
在Sub Main 或者 启动窗口的Load事件里添加代码
If My.Application.CommandLineArgs.Count 0 AndAlso My.Computer.FileSystem.FileExists(My.Application.CommandLineArgs(0)) Then‘参数不为空且文件存在
Dim s As New IO.StreamReader(My.Application.CommandLineArgs(0))
MsgBox(s.ReadToEnd)
End If
vb.net选中文件路径你还可以处理更多的命令行参数。
关于命令行参数
Q2: vb.net从文件路径中获取文件名
获取方法,参考实例如下:
'获取路径名各部分: 如: c:\dir1001\aaa.txt
'获取路径路径 c:\dir1001\
Public Function GetFileName(FilePathFileName As String) As String '获取文件名 aaa.txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
GetFileName Mid(FilePathFileName, J + 1, i)
End Function
''获取路径路径 c:\dir1001\
Public Function GetFilePath(FilePathFileName As String) As String '获取路径路径 c:\dir1001\
On Error Resume Next
Dim J As Integer
J InStrRev(FilePathFileName, "\")
GetFilePath Mid(FilePathFileName, 1, J)
End Function
'获取文件名但不包括扩展名 aaa
Public Function GetFileNameNoExt(FilePathFileName As String) As String '获取文件名但不包括扩展名 aaa
On Error Resume Next
Dim i As Integer, J As Integer, k As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
k InStrRev(FilePathFileName, ".")
If k 0 Then
GetFileNameNoExt Mid(FilePathFileName, J + 1, i - J)
Else
GetFileNameNoExt Mid(FilePathFileName, J + 1, k - J - 1)
End If
End Function
'===== '获取扩展名 .txt
Public Function GetFileExtName(FilePathFileName As String) As String '获取扩展名 .txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, ".")
If J 0 Then
GetFileExtName ".txt"
Else
GetFileExtName Mid(FilePathFileName, J, i)
End If
End Function
Q3: 如何实现VB.NET获取程序运行路径
System.Environment.CurrentDirectory
这才是vb.net的获取程序运行路径的方法
Q4: 求VB.NET获取文件路径的方法
Dim my_path() As String = System.IO.Directory.GetFiles("d:\", "文件名", IO.SearchOption.AllDirectories)
因为有可能在多个地方vb.net选中文件路径,所以进行vb.net选中文件路径了全盘搜索vb.net选中文件路径,歌曲vb.net选中文件路径的所有地址路径在数组my_path中
Q5: VB.net怎么弹出文件夹路径选择框
选择文件夹 在工具箱 - 对话框 里选择 FolderBrowserDialog 添加 到设计器中
然后 代码写在 按钮事件里
FolderBrowserDialog1.ShowDialog()
textbox1.text =FolderBrowserDialog1.SelectedPath
选择文件 在工具箱 - 对话框 里选择 OpenFileDialog
把 OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName
写到按钮事件下
如图
点击按钮会弹出 通用对话框 选择好路径后 确定 ,编辑框里就会显示选择的路径
vb.net选中文件路径的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb选择打开文件路径、vb.net选中文件路径的信息别忘了在本站进行查找喔。






