linkItemAtURL :toURL:error:
Creates a hard link between the items at the specified URLs.
Parameters
- srcURL
- The file URL that identifies the source of the link. The URL in this parameter must not be a file reference URL; it must specify the actual path to the item. The value in this parameter must not be
nil
. - dstURL
- The file URL that specifies where you want to create the hard link. The URL in this parameter must not be a file reference URL; it must specify the actual path to the item. The value in this parameter must not be
nil
. - error
- On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify
nil
for this parameter if you do not want the error information.
Return Value of [NSFileManager linkItemAtURL]
YES
if the hard link was created or NO
if an error occurred. This method also returnsNO
if a file, directory, or link already exists at dstURL.Discussion of [NSFileManager linkItemAtURL]
Use this method to create hard links between files in the current file system. IfsrcURL is a directory, this method creates a new directory at srcURL and then creates hard links for the items in that directory. If srcURL is (or contains) a symbolic link, the symbolic link is copied and not converted to a hard link at dstURL.
Prior to linking each item, the file manager asks its delegate if it should actually create the link. It does this by calling the
fileManager:shouldLinkItemAtURL:toURL:
method; if that method is not implemented it calls the fileManager:shouldLinkItemAtPath:toPath:
method instead. If the delegate method returns YES
, or if the delegate does not implement the appropriate methods, the file manager creates the hard link. If there is an error moving one out of several items, the file manager may also call the delegate’sfileManager:shouldProceedAfterError:linkingItemAtURL:toURL:
orfileManager:shouldProceedAfterError:linkingItemAtPath:toPath:
method to determine how to proceed.
Example of [NSFileManager linkItemAtURL]
if ([fileManager linkItemAtURL :cacheURL toURL:newURL error:&error]) { NSLog(@"%s|%@", __PRETTY_FUNCTION__, @"a hard link is created"); } else { NSLog(@"%s|%@", __PRETTY_FUNCTION__, error); }