The FILE_READLINK function returns the path pointed to by UNIX symbolic links.
Result = FILE_READLINK(Path [, /ALLOW_NONEXISTENT] [, /ALLOW_NONSYMLINK] [, /NOEXPAND_PATH] )
Returns the path associated with a symbolic link.
A scalar string or string array containing the names of the symbolic links to be translated.
Set this keyword to return a NULL string rather than throwing an error if Path contains a non-existent file.
Set this keyword to return a NULL string rather than throwing an error if Path contains a path to a file that is not a symbolic link.
Set this keyword to cause FILE_READLINK to use Path exactly as specified, without expanding any wildcard characters or environment variable names included in the path. See FILE_SEARCH for details on path expansion.
Under Mac OS X, the /etc directory is actually a symbolic link. The following statement reads it and returns the location to which the link points:
path = FILE_READLINK('/etc')
It is possible to have chains of symbolic links, each pointing to another. The following function uses FILE_READLINK to iteratively translate such links until it finds the actual file:
FUNCTION RESOLVE_SYMLINK, path savepath = path ; Remember last successful translation WHILE (path NE '') DO BEGIN path = FILE_READLINK(path, /ALLOW_NONEXISTENT, $ /ALLOW_NONSYMLINK) IF (path NE '') THEN BEGIN ; If returned path is not absolute, use it to replace the ; last path segment of the previous path. IF (STRMID(path, 0, 1) NE '/') THEN BEGIN last = STRPOS(savepath, '/', /REVERSE_SEARCH) IF (last NE -1) THEN path = STRMID(savepath, 0, last) $ + '/' + path ENDIF savepath = path ENDIF ENDWHILE ; FILE_EXPAND_PATH removes redundant things like /./ from ; the result. RETURN, FILE_EXPAND_PATH(savepath) END
Introduced: 5.6