Excel VBA: Regular Expression - get file name

后端 未结 5 1583
轮回少年
轮回少年 2021-01-25 07:30

How do I get just filename (without path and extension)
like \"MyFileName\"
from the following full path?
C:\\A_B\\C.D\\E_\\F0123456789\\G\\MyFileName.txt

5条回答
  •  有刺的猬
    2021-01-25 08:02

        Sub Test()
            Dim fileNameOnly As String
            fileNameOnly = Left$(Split("C:\A_B\C.D\E_\F0123456789\G\MyFileName.txt", "\")(UBound(Split("C:\A_B\C.D\E_\F0123456789\G\MyFileName.txt", "\"))), InStrRev(Split("C:\A_B\C.D\E_\F0123456789\G\MyFileName.txt", "\")(UBound(Split("C:\A_B\C.D\E_\F0123456789\G\MyFileName.txt", "\"))), ".") - 1)
            Debug.Print Strtf    
        End Sub
    

提交回复
热议问题