怎样把一个文件的文件名拿到?
比如:想把“D:\电影\变形金刚[2008fasdfa].asdfasd.fsdf.rmvb”中的文件名(即“变形金刚[2008fasdfa].asdfasd.fsdf”)拿到,怎样实现?

解决方案 »

  1.   


    Private Sub Command1_Click()
        Dim a() As String
        Dim b() As String
        Dim strT As String
        
        strT = "D:\电影\变形金刚[2008fasdfa].asdfasd.fsdf.rmvb"
        
        a = Split(strT, "\")
        b = Split(a(UBound(a)), ".")
        
        MsgBox Replace(a(UBound(a)), "." & b(UBound(b)), "")
        
    End Sub
      

  2.   

    引用Microsoft scripting Runtime
    Private Sub Command1_Click()
        Dim w As Folder
        Dim f As New Scripting.FileSystemObject
        Dim fc As Files
        Set w = f.GetFolder("E:\me\test\myDll")
        Set fc = w.Files
        'Debug.Print fc.Count
        Call ww(fc)
    End SubFunction ww(ByVal vfc As Files)
        Dim s As File
        Dim arr1() As String
        
        For Each s In vfc
            Erase arr1
            arr1 = Split(s.Name, ".")
            Debug.Print Left(s.Name, Len(s.Name) - Len(arr1(UBound(arr1))) - 1)
        Next
    End Function
      

  3.   

    这什么要各到文件名?直接shellexecute嘛.
      

  4.   

    Private Sub Form_Load()
        Dim strData$
        Dim reg As Object
        Dim matches As Object, match As Object
        
        strData = "D:\电影\变形金刚[2008fasdfa].asdfasd.fsdf.rmvb”中的文件名(即“变形金刚[2008fasdfa].asdfasd.fsdf"
        Set reg = CreateObject("vbscript.regexp")
        reg.Global = True
        reg.IgnoreCase = True
        reg.Pattern = "\\([^\\]*?)\.(?=[^\.]*?$)"
        
        Set matchs = reg.Execute(strData)
        
        If matchs.Count = 1 Then
            Debug.Print matchs(0).SubMatches(0)
        End If
    End Sub
      

  5.   


    Private Sub Command1_Click()
       Dim s As String
       s = "D:\电影\变形金刚[2008fasdfa].asdfasd.fsdf.rmvb"
       s = Mid(s, InStrRev(s, "\") + 1, InStrRev(s, ".") - InStrRev(s, "\") - 1)
       Debug.Print s
       
    End Sub
      

  6.   

    Private Function GetFileName(ByVal strFullName As String) As String
        Dim i As Long
        Dim NameLength As Long
        NameLength = Len(strFullName)
        
        For i = NameLength - 1 To 0 Step -1
            If Mid(strFullName, i, 1) = "\" Then
                GetFileName = Mid(strFullName, i + 1, NameLength - i)
                Exit Function
            End If
        Next
    End Function