Getting FolderItem.TrueItem

Hi Folks,

Trying to deal with OS X FolderItem aliases and I’ve got a serious misunderstanding of how to get the TrueItems for Aliases.

      For x = 0 To RealFiles.Ubound
        If InStr(RealFiles(x), "Original Media") <> 0 Then
          // find the real files that are references in the events folders
          f = GetFolderItem(RealFiles(x), FolderItem.PathTypeShell)
          If f.Count > 1 Then
            For y = 1 to f.Count
              If f.Item(y).Alias Then
                Paths.Append f.item(y).TrueItem(0).UnixpathMBS // <== this is the issue, I get an out of bounds
                                                               // error, but y is definitely less than the count
              End If
            Next
          End If
        End If
      Next

I am totally confused as to how to take a given folderitem folder and get the TrueItem for the item when Alias is true.

In the above code, I’m obviously missing something, but I can’t figure it out.

f.item(y) resolves the alias. Use f.TrueItem(y) instead.

Duh! I was reading far too much into the process… :confused:

One step further - if the original item can’t be found, it appears that the TrueItem simply points back to the alias. Is this as expected?

Do you mean Item simply points back to the alias? TrueItem is always the alias. I don’t think that would be expected.

Okay, then I am confused. If the Item is an alias, shouldn’t TrueItem point disclose the original file? The issue I’m witnessing is that if the original file has been deleted, instead of returning an error, the TrueItem is now the same as the Item.

For example:

the original file is /Volumes/MyDrive/Original File
create alias and move alias to new folder
delete /Volumes/MyDrive/Original File

I would now expect an attempt to access f.TrueItem(x) to result in a NOE, but instead it simply returns f.Item(x).

I think you have it backwards. TrueItem does not attempt to resolve aliases–it will be the alias either way. Item, on the other hand, does try to resolve aliases; when it fails, either returning the alias or returning nil would be a sensible thing to do, and Xojo chooses to return the alias.

As many have mentioned, I do have them backwards. And, I now check to see if the TrueItem and the Item are the same and mark that alias as invalid in my UI.

Seems odd, but I can see how returning Nil could get things even more confused if the original file is missing.