Monday, April 22, 2013

NSFileManager createSymbolicLinkAtPath example ios


createSymbolicLinkAtPath :withDestinationPath:error:

Creates a symbolic link that points to the specified destination.
- (BOOL)createSymbolicLinkAtPath:(NSString *)pathwithDestinationPath:(NSString *)destPath error:(NSError **)error
Parameters
path
The path at which to create the new symbolic link. The last path component is used as the name of the link.
destPath
The path that contains the item to be pointed to by the link. In other words, this is the destination of the link.
error
If an error occurs, upon return contains an NSError object that describes the problem. Pass NULL if you do not want error information.
Return Value of [NSFileManager createSymbolicLinkAtPath]
YES if the symbolic link was created or NO if an error occurred. This method also returns NO if a file, directory, or link already exists at path.
Discussion
This method does not traverse symbolic links contained in destPath, making it possible to create symbolic links to locations that do not yet exist. Also, if the final path component in path is a symbolic link, that link is not followed.

Example of [NSFileManager createSymbolicLinkAtPath]

NSString* js_path = [[NSBundle mainBundle] pathForResource:@"js" ofType:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (js_path != nil) {
    NSFileManager *fm = [NSFileManager defaultManager];
    NSString* move_js_path = [NSString stringWithFormat:@"%@/js",  [paths objectAtIndex:0]];
    NSError *error; 
    if ([fm createSymbolicLinkAtPath:move_js_path withDestinationPath:js_path error:&error]) {
    } else {}
}