新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim strAll$, strArr$(), strPath$, strFN$
strAll = "C:\Windows\System\system.dll"
strFN = f_GetFileName(strAll)
Debug.Print strFN
strPath = Left(strAll, Len(strAll) - Len(strFN))
Debug.Print strPath
Debug.Print f_GetFilExtension(strAll)
End Sub
Private Function f_GetFileName(strFN$) '得到不含路径的文件名
f_GetFileName = Mid(strFN, InStrRev(strFN, "\") + 1)
End Function
Private Function f_GetFilExtension(strFN$)
Dim lngA&
lngA = InStrRev(strFN, ".")
If lngA > 0 Then
f_GetFilExtension = Mid(strFN, lngA)
Else
f_GetFilExtension = ""
End If
End Function
运行结果:
system.dll
C:\Windows\System\
.dll