大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
' The file system path we need to split
创新互联公司2013年至今,是专业互联网技术服务公司,拥有项目做网站、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元安福做网站,已为上家服务,为安福各地企业和个人服务,联系电话:13518219792
Dim s As String = "C:\Users\New York\SoHo\abc.doc"
' Split the string on the backslash character
Dim parts As String() = s.Split(New Char() {"\"c})
之后取数组的最后两个 用“\”连接起来就可以了。
当然不能~! Me.OpenFileDialog1. FileNames这个是多选文件时,一个文件数组, 不是单个文件,单个文件用Me. OpenFileDialog1.FileName 而Str(Me.OpenFileDialog1. FileNames) 又是什么意思呢~?把数组转化成字符串~?~~?~? strFileDirectary = Me.OpenFileDialog1.FileName 这样strFileDirectary 得到的是完整的文件路径,不是文件夹 我搞不懂你到底要获得文件路径还是文件所在的文件夹~~?~?
希望采纳
获取方法,参考实例如下:
'获取路径名各部分:
如:
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
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
Then
GetFileExtName
".txt"
Else
GetFileExtName
Mid(FilePathFileName,
J,
i)
End
If
End
Function