AbsolutePath<-> relative path

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

Is there something already done to get absolute path from relative path, and
relative path from absolute path:
Example:
BasePath="c:\a\b\c"
RelativePath="..\e\f\g\..\m"
AbsolutePath=FindAbsolutePath(BasePath, RelativePath)

and the same in other direction
 
AbsolutePath=FindAbsolutePath(BasePath, RelativePath)

AbsolutePath = Path.GetFullPath(Path.Combine(BasePath, RelativePath))

and the same in other direction

Nothing in the BCL but there's the native API PathRelativePathTo.



Mattias
 
Nothing in the BCL but there's the native API PathRelativePathTo.

How do I use it from VB.NET?
 
How do I use it from VB.NET?

Declare Auto Function PathRelativePathTo Lib "shlwapi.dll" (ByVal
pszPath As StringBuilder, ByVal pszFrom As String, ByVal dwAttrFrom As
Integer, ByVal pszTo As String, ByVal dwAttrTo As Integer) As Boolean

....

Const FILE_ATTRIBUTE_DIRECTORY As Integer = &H10
Dim relativePath As New StringBuilder(260)
PathRelativePathTo(relativePath, "C:\Windows\System32",
FILE_ATTRIBUTE_DIRECTORY, "C:\Program Files\Microsoft Visual Studio
..NET 2003", FILE_ATTRIBUTE_DIRECTORY)
Console.WriteLine(relativePath)

' Prints ..\..\Program Files\Microsoft Visual Studio .NET 2003



Mattias
 
Thank you. I deceided to implement my own .NET classs for that
(absolute2relative and relative2absolute ). Took half a day but now I have
just what I wanted :).
 
Back
Top