VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Take a base path of your web page, along with the path of a file (image, background, etc.) and conv

by TerranRiCH (5 Submissions)
Category: Internet/HTML
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Thu 26th July 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Take a base path of your web page, along with the path of a file (image, background, etc.) and convert it to a relative path (like

Rate Take a base path of your web page, along with the path of a file (image, background, etc.) and conv



    ' TAKE APART BASEPATH...
    For i = Len(BasePath) To 1 Step -1
        If Mid(BasePath, i, 1) = "\" Then
            j = i
            Exit For
        End If
    Next i
    BaseDirectory = Left(BasePath, j)
    BaseFile = Right(BasePath, Len(BasePath) - 1)
    
    ' GET EACH DIRECTORY NAME AND STORE INTO AN ARRAY.
    ReDim BaseDir(CountChar(BasePath, "\") - 1) As String
    iCounter = 1
    For i = 1 To Len(BasePath)
        If iCounter = CountChar(BasePath, "\") Then Exit For
        If Mid(BasePath, i, 1) = "\" Then
            iFirstChar = i
            For j = (i + 1) To Len(BasePath)
                If Mid(BasePath, j, 1) = "\" Then
                    iLength = j - i
                    Exit For
                End If
            Next j
            BaseDir(iCounter) = Mid(BasePath, iFirstChar, iLength)
            iCounter = iCounter + 1
        End If
    Next i
        If InStr(SpecifiedPath, BaseDirectory) Then
            ' If SpecifiedPath is INSIDE BasePath, then just get the part
            ' of the SpecifiedPath MINUS the BaseDirectory...
            GetRelativePath = Right(SpecifiedPath, Len(SpecifiedPath) - Len(BaseDirectory))
            GetRelativePath = ReplaceString(GetRelativePath, "\", "/")
        Else
            For i = 1 To Len(BasePath)
                If Mid(BasePath, i, 1) <> Mid(SpecifiedPath, i, 1) Then
                    j = i
                    Exit For
                End If
            Next i
            PartialDirectory = Right(SpecifiedPath, Len(SpecifiedPath) - j + 1)
            For i = 1 To CountChar(BasePath, "\") - 1
                If Not InStr(SpecifiedPath, BaseDir(i)) Then
                    j = i
                    Exit For
                End If
            Next i
            PartialPath = StringOfCharacters("../", CountChar(BasePath, "\") - j - 1)
            GetRelativePath = PartialPath & PartialDirectory
        End If
End Function

Download this snippet    Add to My Saved Code

Take a base path of your web page, along with the path of a file (image, background, etc.) and conv Comments

No comments have been posted about Take a base path of your web page, along with the path of a file (image, background, etc.) and conv. Why not be the first to post a comment about Take a base path of your web page, along with the path of a file (image, background, etc.) and conv.

Post your comment

Subject:
Message:
0/1000 characters