Get file name


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'**********************************************************************************************************
' Name:                 getFileName
' Author:               mielk | 2014-02-26
'
' Comment:              Function returns the name and extension of the given full filepath.
'
' Parameters:
'   filepath            The path of a file which name is to be returned.
'
' Returns:
'   String              The name of the given file (including extension).
'                       If the given parameter is not a proper file path, an empty String is returned.
'
'
' --- Changes log -----------------------------------------------------------------------------------------
' 2012-03-26        mielk       Function created.
'**********************************************************************************************************
Public Function getFileName(filepath As String) As String
    Const METHOD_NAME As String = "getFileName"
    '------------------------------------------------------------------------------------------------------
    Dim slashPosition As Integer
    '------------------------------------------------------------------------------------------------------

    slashPosition = VBA.InStrRev(filepath, "\")
    getFileName = VBA.Mid(filepath, slashPosition + 1)

End Function