首页 /编程语言和算法/VB6/VBA/ASP
 VB6 获得文件路径strPath,得到不含路径的文件名f_GetFileName和文件名后缀f_GetFilExtension
2024年4月10日 23:26

新建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


 
全部回复(0)
首页 | 电脑版 |