返回列表 发帖

VB 获取路径名各部分 (获取文件路径,获取文件名,获取文件扩展名)

'============获取路径路径 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
宁做真小人,不做伪君子

TOP

'===========获取文件名但不包括扩展名 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 = 0 Then
        GetFileNameNoExt = Mid$(FilePathFileName, J + 1, i - J)
    Else
        GetFileNameNoExt = Mid$(FilePathFileName, J + 1, k - J - 1)
    End If

End Function
宁做真小人,不做伪君子

TOP

'======= '获取扩展名 .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 = 0 Then
        GetFileExtName = ".txt"
    Else
        GetFileExtName = Mid$(FilePathFileName, J, i)
    End If
End Function
宁做真小人,不做伪君子

TOP

返回列表