On Dec 21, 2006, at 10:02 AM, Charles Yeomans wrote:

On Dec 21, 2006, at 10:51 AM, Michael Rebar wrote:

On 12/21/06 6:30 AM, "Lennox Jacob" <[EMAIL PROTECTED]> wrote:

Hello,

How do I detect a defective alias programatically?

Mac OS gives this message:
The alias „myApp‰ alias could not be opened, because the original cannot be
found

I would like my app to be able to do that when I have a defective alias.

Kindly advise.

Thanks.

Lennox

If folderItem.TrueChild for an existing alias returns nil you've, likely got a defective alias (depends a bit on your definition of defective alias).

Almost -- TrueChild returns the file, unresolved. So I think he would want to check to see whether Child is nil.

In a program I wrote not long ago to help find errant aliases after cloning a hard drive, I found that a broken, or orphaned alias file would resolve to itself, not be nil, when the file it points to no longer exists as seen in the following code:

aliasedFile = currentItem.Parent.Child(aliasFileName) // resolve the alias if aliasedFile.equals(currentItem) then // both same file? if so, flag it as "Orphan" gbadAliases.Append new errantAlias(dispName, "O", currentItem, aliasedFile) // add to arrray
    gOrphanCount = gOrphanCount + 1
    stOrphanCount.text = format(gOrphanCount,"###,###")
    stOrphanCount.Refresh
       .
       .
       .

Where the "equals" extension for the FolderItem is coded as follows:

  Function equals(Extends f As FolderItem, g As FolderItem) As Boolean
// this method is passed two folderitems. it returns true if the two folderitems
    // refer to the same file/folder and false if they don't
    if f = nil  or g = nil then
      return false
    else
      #if TargetMacOS
Return (f.MacVRefNum = g.MacVRefNum and f.MacDirID = g.MacDirID and f.Name = g.Name)
      #endif
      #if TargetWin32
        return StrComp(f.AbsolutePath, g.AbsolutePath,0) = 0
      #endif
    end if
  End Function

I just never got a return of "nil" when resolving an alias. I either got a valid folderitem of the file the alias pointed to, or I got a folderitem pointing to the alias file itself when the original file no longer existed.

=== A Mac addict in Tennessee ===

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to