destinationOfSymbolicLinkAtPath :error:
Returns the path of the item pointed to by a symbolic link.
Parameters
- path
- The path of a file or directory.
- error
- If an error occurs, upon return contains an
NSError
object that describes the problem. PassNULL
if you do not want error information.
Return Value of [NSFileManager destinationOfSymbolicLinkAtPath]
An
NSString
object containing the path of the directory or file to which the symbolic link path refers, or nil
upon failure. If the symbolic link is specified as a relative path, that relative path is returned.
Example of [NSFileManager destinationOfSymbolicLinkAtPath]
- (
NSString
*)stringByConditionallyResolvingSymlink
{
// Get the path that the symlink points to
NSString
*symlinkPath =
[[
NSFileManager
defaultManager
]
destinationOfSymbolicLinkAtPath
:
self
error
:
NULL
];
if
(!symlinkPath)
{
return
nil
;
}
if
(![symlinkPath
hasPrefix
:
@"/"
])
{
// For relative path symlinks (common case), resolve the relative
// components
symlinkPath =
[[
self
stringByDeletingLastPathComponent
]
stringByAppendingPathComponent
:symlinkPath];
symlinkPath = [symlinkPath
stringByStandardizingPath
];
}
return
symlinkPath;
}