求在VB中判断文件路径(如c:\windows\test.exe的样式)的正则表达式
请写全部过程谢谢

解决方案 »

  1.   

    Public Function GetFileNameOfPath(Path As String)On Error GoTo PROC_ERR:    Dim I As Integer, ArrayLen As Integer, temp As Integer
        
        ArrayLen = Len(Path)
        For I = ArrayLen To 1 Step -1
            If Mid(Path, I, 1) = "\" Then
                temp = I
                Exit For
            End If
        Next I
            
        If ArrayLen <= 3 Then
            GetFileNameOfPath = ""
        Else
            GetFileNameOfPath = Right(Path, (ArrayLen - temp))
        End If
        
    PROC_EXIT:
        Exit FunctionPROC_ERR:
        GoTo PROC_EXIT
        
    End Function
      

  2.   

    有函数啊
    FileExists(filename)
      

  3.   

    用dir函数: dir(path) 如果path存在,则返回正确路径,否则返回空.
      

  4.   

    '引用 Microsoft VBScript Regular ExpressionsFunction b(s As String, p As String) As Boolean
        
    On Error GoTo 100
        
        Dim myReg As RegExp
        Set myReg = New RegExp
        myReg.IgnoreCase = True
        myReg.Pattern = p
        b = myReg.Test(s)
        Exit Function
    100:
        b = False
    End Function'调用:
        Dim p As String
        p = "^[a-zA-Z]:(\\[^\\/:""""<>\|]+)+$"
        MsgBox b(c:\windows\test.exe, p)
      

  5.   

    sorry:纠正一下:'调用: 
        Dim p As String 
        p = "^[a-zA-Z]:(\\[^\\/:"""" < >\ ¦]+)+$" 
        MsgBox b("c:\windows\test.exe", p)
      

  6.   

    这样对根目录的判断是否有问题:如"C:"
    是否可改为如下: @"^[A-Z|a-z]:(\\|(\\[^\\/:*""""?<>\¦]+)+){1}$"