dim p as string 
p="d:\tool\tm.html"
如何获得文件路径(D:\Tool),文件名(tm),文件后缀名(html)。UP 有分.

解决方案 »

  1.   

    '检测文件类型函数
    Function chkFileType(file As String) As String
        '获取文件类型
        If chkFile = "" Then Exit Function
        '文件无后缀名
        chkFileType = Right(file, Len(file) - InStrRev(file, ".", -1))
    End Function给大家一点参考。
      

  2.   

    '检测文件类型函数
    Function chkFile(file As String) As String
        '获取文件类型
        chkFile = Right(file, InStr(file, "."))
        If chkFile = "" Then Exit Function
        '文件无后缀名
        chkFile = Right(file, Len(file) - InStrRev(file, ".", -1))
        '文件后缀名为chkFile
    End Function刚才贴出的有错误,现在改正。文件的后缀名为任意长度都可以获取了。
    望那位好心,给出其余的代码.
      

  3.   

    Dim p As String
    Dim i, j As Integerp = "d:\tool\tm.html"
    i = InStr(1, StrReverse(p), "\")
    j = InStr(1, StrReverse(p), ".")MsgBox "路径:" & Left(p, Len(p) - i)
    MsgBox "文件名:" & Mid(p, i + 1, i - j - 1)
    MsgBox "后缀名:" & Right(p, j - 1)
      

  4.   

    先找出“所在的位置,然后找到第一个\的位置,用mid函数就可以得到路径了,其他同样的方法。
      

  5.   

    Function SplitFileName(file As String,strPath as string ,strfilter as string ,strName as string) as integer
        '获取文件类型
        dim  i as integer,j as integer;
        i=instrrev(file,".")
        if(i<1)  then
             SplitFileName=-1
            return
         end if
          strfilter=right(file,len(file)-i)
         j=instrrev(file,"\")
        if(j<1)  then
             SplitName=-1
            return
         end if
        strName=mid(file,j+1,i-j-1)
        strPath=left(file,j-1)
       End Function
      

  6.   

    请大家用这个文件名试一下。
    D:\my work\我的 文档kk\pp 分.txt文档
    如果没有错误再贴代码出来吧。