GetPapa, GetPapa_URL, GetPapa_Sep, GetSon, GetSon_

Gets that parent folder name giving a full path, or gets the child folder, Can be used in PC or Mac, also a version for URL papa and Son
GetPapa, GetPapa_URL, GetPapa_Sep, GetSon, GetSon_uRL, GetSon_Sep
Updated 2021-08-11: Adding ability to remove separator if found at end of path, to get actual Son in GetSon_Sep

CodeFunctionName
What is this?

Public

Tested

Original Work
' Gets parent of a file/folder or the child, Can be used in PC or Mac
' GetPapa, GetPapa_URL, GetPapa_Sep, GetSon, GetSon_uRL, GetSon_Sep
Function GetSon(FullPath)
    GetSon = GetSon_Sep(FullPath)
End Function
Function GetPapa(Optional FullPath= "This")
    If FullPath= "This" Then FullPath= Thisworkbook.Path
    GetPapa = GetPapa_Sep(FullPath)
End Function
Function GetSon_URL(FullPath)
    GetSon_URL = GetSon_Sep(FullPath, "/")
End Function
Function GetPapa_URL(FullPath)
    GetPapa_URL = GetPapa_Sep(FullPath, "/")
End Function
Function GetSon_Sep(FullPath, Optional Separator = "\")
    ' Reads the son of a string based on certain separator, default is \ for file path
    If Application.OperatingSystem Like "*Mac*" And Separator = "\" Then Seperater = ":"
    If UCase(Right(FullPath, Len(Separator))) = UCase(Separator) Then
        lastslash = InStrRev(Left(FullPath, Len(FullPath) - Len(Separator)) , Separator)
    Else
        lastslash = InStrRev(FullPath, Separator)
    End If
    GetSon_Sep = Mid(FullPath, lastslash + 1)
End Function
Function GetPapa_Sep(FullPath, Optional Separator = "\")
    ' Reads the father of a string based on certain separator, default is \ for file path
    If Application.OperatingSystem Like "*Mac*" And Separator = "\" Then Seperater = ":"
    lastslash = InStrRev(FullPath, Separator)
    GetPapa_Sep = FullPath
    If lastslash > 0 Then GetPapa_Sep = Left(FullPath, lastslash - 1)
End Function

FullPath
or
FullPath, Optional Separator

Views 3,488

Downloads 1,391

CodeID
DB ID

ANmarAmdeen
602
Attachments
Revisions

v4.0

Friday
May
19
2023