取路径:
Public Function GetFileFolder(ByVal sFilename As String) As String
   Dim iEnd
   
   iEnd = InStrRev(sFilename, "/")
   If iEnd = 0 Then
      iEnd = InStrRev(sFilename, "\")
   End If
   If iEnd > 0 Then
      GetFileFolder = Mid(sFilename, 1, iEnd)
   Else
      GetFileFolder = ""
   End If
End Function取文件名:
Public Function GetFileName(ByVal sFilename As String) As String
   Dim iStart
   
   iStart = InStrRev(sFilename, "/") + 1
   If iStart = 0 Then
      iStart = InStrRev(sFilename, "\") + 1
   End If
   If iStart = 0 Then
      iStart = 1
   End If
   GetFileName = Mid(sFilename, iStart)
End Function

解决方案 »

  1.   

        Dim myarr
        Dim strpath As String
        myarr = Split("c:\game\rpl\pal.exe", "\", -1, vbTextCompare)
        strpath = myarr(UBound(myarr))
        MsgBox strpath
      

  2.   

    以上的方法不是很全面,比如网络上的文件:\\Net\ABC\Test.txt,用上面的方法用不行了,还要完善一下。
      

  3.   

    Dim a As New Scripting.FileSystemObject
    Dim r As String
    r = a.GetFileName("c:\game\rpl\pal.exe")
    Set a = Nothing
      

  4.   

    To triumph:
        对于\\Net\ABC\Test.txt这种格式也是一样的
    因为取得的字符串是最后面的Test.txt
      

  5.   

    To triumph:
        对于\\Net\ABC\Test.txt这种格式也是一样的
    因为取得的字符串是最后面的Test.txt
      

  6.   

    如果只要文件名的话用SPLIT函数就可以了,真的很简单
      

  7.   

    我试了BrentIvan(Ivan)的方法,取路径的代码有用,但取文件名的代码没用,Why?有谁试过没
    有?!
      

  8.   

    to aldz(阿蓝德猪) 
    当然没用了!
    要改成这样!
    取路径:
    Public Function GetFileFolder(ByVal sFilename As String) As String
      Dim iEnd
      
      iEnd = InStrRev(sFilename, "/")
      If iEnd = 0 Then
          iEnd = InStrRev(sFilename, "\")
      End If
      If iEnd > 0 Then
          GetFileFolder = Mid(sFilename, 1, iEnd)
      Else
          GetFileFolder = ""
      End If
    End Function取文件名:
    Public Function GetFileName(ByVal sFilename As String) As String
      Dim iStart
      
      iStart = InStrRev(sFilename, "/")
      If iStart = 0 Then
          iStart = InStrRev(sFilename, "\")
      End If
    iStart=iStart+1
    GetFileName = Mid(sFilename, iStart)
    End Function