Public Function GetFileName(ByVal FullPathName As String, Optional ByVal NoExtName As Boolean = False) As String
'从指定全路径中找到文件名
'FullPathName指定全路径
'返回值:包含的文件名
Dim I As Long, J As Long
Dim filename As String, FileNameNoExt As String
FullPathName = Trim(FullPathName)
I = InStrRev(FullPathName, "\")
J = Len(FullPathName)
If I = 0 Then Exit Function
filename = Mid(FullPathName, I + 1, J - I)
I = InStrRev(filename, ".")
J = Len(filename)
If I = 0 Then Exit Function
FileNameNoExt = Mid(filename, 1, I - 1)
If NoExtName = True Then
GetFileName = FileNameNoExt
Else
GetFileName = filename
End If
End Function
Dim Wenjianming As String '文件名
Dim lujingB As String '半个路径,既没有文件名的目录
Dim N1 As Integer
N1 = InStrRev(Lujing1, "\", , vbTextCompare)
Wenjianming = Right$(Lujing1, Len(Lujing1) - N1)
lujingB = Left$(Lujing1, N1)
MsgBox Wenjianming
MsgBox lujingB
guduguoker的答案正确
dim Path as string,FileName as string ,S() as string
Path=路径
s=split(path,"\")
FileName=s(ubound(s))
判断最后一个“/”的位置,然后根据此数据取后面的字符即可。