'  FF_PATHNAME
'  解析路径/文件名以提取组件部分
'  此函数计算一个文本路径/文件文本名称，并返回名称的请求的一部分。该功能是严格的字符串解析单独之一。

'  选择下列之一，用于指定所请求的部分：
'  FULL
'        返回完整的路径文件名称，就是 sFilespec 参数。 
'  PATH
'        返回路径/文件名的路径部分。这是文本包括到最后的反斜杠（\）或冒号（：）。
'  NAME
'        返回路径文件名称的名称部分。这是右边的最后一个反斜杠 (\) 或冒号 （:），之后的最后一个句点 （.） 结尾的文本。
'  EXTN
'        返回的路径/文件名的扩展部分。这是最后一个句点 （.） 在字符串加到它右侧的文本。
'  NAMEX
'        返回的名称和EXTN部分的总和。
'  Function FF_Pathname( ByRef sOption   as String, _
'                        ByRef sFilespec as String _
'                        ) as String
''
''  FF_PATHNAME
''  Parse a path/file name to extract component parts
''
''  This function evaluates a text path/file text name, and returns a requested 
''  part of the name. The functionality is strictly one of string parsing alone. 
''  
''  sOption one of the following words which is used to specify the requested part:
''  FULL
''        Returns the full path/file name, just as given in the sFilespec parameter. 
''  PATH
''        Returns the path portion of the path/file Name. That is the text up to and 
''        including the last backslash (\) or colon (:).
''  NAME
''        Return the name portion of the path/file Name. That is the text To the right 
''        of the last backslash (\) or colon (:), ending just before the last period (.).
''  EXTN
''        Returns the extension portion of the path/file name. That is the last 
''        period (.) in the string plus the text to the right of it.
''  NAMEX
''        Returns the name and the EXTN parts combined.
'' 
Function FF_Pathname( ByRef sOption   as String, _
                      ByRef sFilespec as String _
                      ) as String

    Dim nLen as Integer = Len(sFilespec)
    Dim s    as String  = sFilespec
    Dim st   as String  = ""
    Dim i    as Integer = 0
    
    If nLen = 0 Then Return sFilespec
    
    Select Case UCase(Trim(sOption))
       Case "FULL" 
          Return s
       
       Case "PATH"
          i = InStrRev(s, Any ":\/")
          If i Then 
             Return Left(s, i)
          Else
             Return ""
          End If
             
       Case "NAME"
          ' Get the full filename
          i = InStrRev(s, Any ":/\")
          st = IIf( i, Mid(s, i + 1), s )
          ' Get the name portion
          i = InStrRev(st, ".")
          st = IIf( i, Left(st, i - 1), st )
          Return st
       
       Case "EXTN"
          ' Get the full filename
          i = InStrRev(s, Any ":/\")
          st = IIf( i, Mid(s, i + 1), s )
          ' Get the extension
          i = InStrRev(st, ".")
          st = IIf( i, Mid(st, i), "" )
          Return st
       
       Case "NAMEX"
          i = InStrRev(s, Any ":/\")
          If i Then Return Mid(s, i + 1)
             
    End Select
    
    Return s
    
End Function


