DirectoryIterator and Mac Alias

Is there a way to make the DirectoryIterator go through Mac aliases (not symbolic links)?

The isLink() doesn't work (as I guess it's only for symbolic links), but even if I give the full path to the alias to the DirectoryIterator it can't find any files in it.



The DirectoryIterator won't do that (if it followed them then I think it could get into infinite loops)

Doesn't File::getLinkedTarget() return the aliased target though?

Unfortunately not.

I tried several times, not sure if I'm doing something wrong but basically this:

File dir = File("/path/to/alias");
File aliasDir = dir.getLinkedTarget();


returns this:


No change at all. I think that getFileLink check only symbolic links and not aliases.

What can I do?

After further tests I can confirm that getLinkedTarget() works only on symbolic links and NOT on aliases.

How can I manage aliases? They are way more common than symbolic links (and also easier to manage).


Not really a priority for us to look at this, but it may be a one-liner if you want to do the research into how aliases work..

You need to use  FSPathMakeRef, FSResolveAliasFileWithMountFlags and FSRefMakePath


Awesome, thanks a lot!

Those were all deprecated long ago, weren't they?

Yep. Working fine though.


Here is the new way (untested)