FolderItem.GetRelative not working as expected

Hello

I try to get a path relative from another path. I read the docs and it shows a perfect example of how to do, so this is my testing code:

[code]Dim f, g As FolderItem
f = GetOpenFolderItem("")
g = f.GetRelative(f.GetSaveInfo(SpecialFolder.ApplicationData.Child(“xxxxxx”), 0))

MsgBox(g.NativePath)[/code]

When I select a file with the GetOpenFolderItem in this folder:

I still get the full path, not the relative. What I expect is something like this: “assets/heightmaps/default.png”

What is wrong with this small piece of code?

Thanks!

The “relative” part refers to the string being passed in, not the resulting folderitem.

Hmh, I don’t get it. I might be my lack of the English language. But what does .GetRelative do actually?

The docs state:

So I expect a folderitem based on the string passed to it, but I just get the full path, not based on anything?

http://documentation.xojo.com/index.php/FolderItem.GetRelative

given a base folderitem (the starting point)
and a relative path this will return the folderitm that is at the relative location from the starting point

it has nothing to do with getting a relative path as a string

This is incredibly barbaric and will not work in reverse (if the base is deeper than the child) but should get you started on what you’re looking to try to get:

[code]Public Function NativePathRelativeTo(extends fBase as FolderItem, fChild as FolderItem) as String
if fBase = nil or fChild = nil then return “”

dim sBasePath as String = fBase.Parent.NativePath
dim sChildPath as String = fChild.NativePath

return sChildPath.Replace(sBasePath, “”)
End Function
[/code]

Thanks Tim, I figured something out amost the same way you did :slight_smile:

Altough the naming in Xojo is still wrong imho.
a GetRelative function should get a relative.
The functions should be renamed to FromRelative

[quote=338778:@Mathias Maes]Thanks Tim, I figured something out amost the same way you did :slight_smile:

Altough the naming in Xojo is still wrong imho.
a GetRelative function should get a relative.
The functions should be renamed to FromRelative[/quote]
Unfortunately it can’t be renamed without potentially breaking existing code because this method has been around for so long and we really try to avoid that.

Yeah, I totally get that.
Thanks for your answer Greg! Keep up the great work at Xojo! My ‘complaint’ wasn’t really a rant or something. More like a hint, because it can be confusing for newcomers (like I’m still am sometimes).

[quote=338787:@Mathias Maes]Yeah, I totally get that.
Thanks for your answer Greg! Keep up the great work at Xojo! My ‘complaint’ wasn’t really a rant or something. More like a hint, because it can be confusing for newcomers (like I’m still am sometimes).[/quote]
You could still file a feature request for the new framework. One of the things we’re trying to do is resolve naming issues like this.