By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,386 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,386 IT Pros & Developers. It's quick & easy.

AbsolutePath<-> relative path

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
>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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2

P: n/a
> Nothing in the BCL but there's the native API PathRelativePathTo.

How do I use it from VB.NET?

Nov 21 '05 #3

P: n/a
Nothing in the BCL but there's the native API PathRelativePathTo.


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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4

P: n/a
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 :).

"Mattias Sjögren" <ma********************@mvps.org> schrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP09.phx.gbl...
Nothing in the BCL but there's the native API PathRelativePathTo.


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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.