6个回答
展开全部
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
'从指定全路径中找到文件名
'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
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))
Path=路径
s=split(path,"\")
FileName=s(ubound(s))
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
判断最后一个“/”的位置,然后根据此数据取后面的字符即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询