I have control where the user can drop files.
If the user drop an alias/link, the DropObject event provide me the TrueItem, the alias file, not the real one.
Now, I can see it’s an alias form the Alias property, but how I can reach the pointed item?
If you check out the docs at http://documentation.xojo.com/index.php/FolderItem.TrueItem there is an example of how to get the real item (not the alias/shortcut)
Thanks shao, but your example is valid when my folderItem is a directory and I want to get a contained item.
My situation is different: the DropObject event already provide me a file and I want to reach to original pointed item.
Massimo, it seems you did not read the docs page completely. See this:
item = item.Parent.Child(item.Name)
Or use FolderItem.Item if your Xojo version support it.
Oh that’s what I was looking for, but the dual behavior of the method and my carelessness fooled me.
Thanks Thomas and also Shao that initially pointed me to the right solution.
I also had some problems with it right now.
This method works (for me) with both ( GetFolderItem / GetTrueFolderItem).
Public Function getFileFromAlias(file As FolderItem) as folderitem
dim f, g as FolderItem
if file.Alias = True then
f = file.Parent.Child(file.Name)
g = f.Parent.Child(f.Name)
else
g = file.Parent.Child(file.Name)
end if
Return g
End Function
dim f As FolderItem
f = getFileFromAlias(GetFolderItem _
("/path/to/your/file.ext", _
FolderItem.PathTypeShell))
or
dim f As FolderItem
f = getFileFromAlias(GetTrueFolderItem _
("/path/to/your/file.ext", _
FolderItem.PathTypeShell))
That first part looks quite wrong or at least redundant.
You can test that Alias property before doing the entire parent.child() thing, and you should also check that parent is not nil (which is the case if it’s the root dir). So, this would be safe and sane:
Public Function ResolveAlias(extends file As FolderItem) as FolderItem
if file.Alias and file.parent <> nil then
file = file.Parent.Child(file.Name)
end if
Return file
End Function
The “extends” keywork let you use it like this:
dim f as FolderItem = obj.FolderItem // e.g. from a DropObject event
f = f.ResolveAlias
Thanks, but that does not work for me (in Linux)
tested with
/usr/share/icons/gnome/256x256/mimetypes/ascii.png
is alias to
/usr/share/icons/gnome/256x256/mimetypes/text-x-generic.png
[code]dim f as FolderItem
dim result() as string
f = GetFolderItem _
("/usr/share/icons/gnome/256x256/mimetypes/ascii.png", _
FolderItem.PathTypeNative)
result.Append "Alias: " + str(f.Alias) + EndOfLine
f = f.ResolveAlias
result.Append f.NativePath[/code]
Result:
Alias: False
/usr/share/icons/gnome/256x256/mimetypes/text-x-generic.png/
using f = GetTrueFolderItem …
Result:
Alias: True
/usr/share/icons/gnome/256x256/mimetypes/text-x-generic.png/
always a slash at the end
changed line 1 in your method to
if file.Alias = false and file.parent <> nil then
and using GetFolderItem
Result:
Alias: False
/usr/share/icons/gnome/256x256/mimetypes/text-x-generic.png
(that is ok but that is not logical)