Search Tools Links Login

Creates a relative path from one file or folder to another.

Creates a relative path from one file or folder to another.

Original Author: Alexander Triantafyllou


Private Declare Function PathRelativePathTo Lib "shlwapi.dll" Alias "PathRelativePathToA" (ByVal pszPath As String, ByVal pszFrom As String, ByVal dwAttrFrom As Long, ByVal pszTo As String, ByVal dwAttrTo As Long) As Long
Private Const MAX_PATH As Long = 260
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
' Creates a relative path from one file or folder to another.
' made by Alexander Triantafyllou
' usage relative_path=get_relative_path_to(root_path,file_path)
' get_relative_path_to("d:acd","d:aindex.html") will return
' "....index.html"
' use FILE_ATTRIBUTE_DIRECTORY if the path is a directory
' or FILE_ATTRIBUTE_NORMAL if the path is a file
Public Function get_relative_path_to(ByVal parent_path As String, ByVal child_path As String) As String
Dim out_str As String
Dim par_str As String
Dim child_str As String
out_str = String(MAX_PATH, 0)
par_str = parent_path + String(100, 0)
child_str = child_path + String(100, 0)
PathRelativePathTo out_str, par_str, FILE_ATTRIBUTE_DIRECTORY, child_str, FILE_ATTRIBUTE_NORMAL
out_str = StripTerminator(out_str)
'MsgBox out_str
get_relative_path_to = out_str
End Function
'Remove all trailing Chr$(0)'s
Function StripTerminator(sInput As String) As String
Dim ZeroPos As Long
ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then
  StripTerminator = Left$(sInput, ZeroPos - 1)
  StripTerminator = sInput
End If
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 91 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.