Split file path if certain directory is used

ringjensen

New member
Local time
Today, 12:14
Joined
Jul 29, 2010
Messages
6
Hi

English isn't my native - hope I can explain myself :-) even if it's sounds crazy

Please! Need to split a file path if it meets certain criteries.

ex.. "c:\folder\subfolder1\subfolder2\subfolder criteria\subfolder4\subfolder5\"

Need to break it up like

"c:\folder\subfolder1\subfolder2\ and
subfolder criteria\subfolder4\subfolder5\"

Thanks in advance
 
Solved: Split file path if certain directory is used

Got it :-)... a trim function did the job... with this function I can manipulate the positions and change from Left to Right and vice versa perfect ... the substring (text) is my criteria foldername ...

thanks to "Chip Pearson and Pearson Software Consulting, LLC " - "www.cpearson.com"

Code:
Public Function TrimToChar(Text As String, TrimChar As String, _
    Optional SearchFromRight As Boolean = False) As String
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' TrimToChar
' This function returns the portion of the string Text that is to the left of
' TrimChar. If SearchFromRight is omitted or False, the returned string
' is that string to the left of the FIRST occurrence of TrimChar. If
' SearchFromRight is True, the returned string is that string to the left of the
' LAST occurrance of TrimToChar. If TrimToChar is not found in the string,
' the entire Text string is returned. TrimChar may be more than one character.
' Comparison is done in Text mode (case does not matter).
' If TrimChar is an empty string, the entire Text string is returned.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim Pos As Integer

    ' Test to see if TrimChar is vbNullString. If so, return the whole string. If we
    ' don't test here and used InStr as in the next logic block, an empty string would
    ' be returned.
    If TrimChar = vbNullString Then
        TrimToChar = Text
        Exit Function
    End If

    ' find the position in Text of TrimChar
    If SearchFromRight = True Then
        ' search right-to-left
        Pos = InStrRev(Text, TrimChar, -1, vbTextCompare)
    Else
        ' search left-to-right
        Pos = InStr(1, Text, TrimChar, vbTextCompare)
    End If
    ' return the sub string
    If Pos > 0 Then
        TrimToChar = Left(Text, Pos - 1)
    Else
        TrimToChar = Text
    End If

End Function
 

Users who are viewing this thread

Back
Top Bottom