Hi,
I've been struggling with for quite a while now, what i want to achieve is create an alias of a folder at some location. The alias would also be a folder like we have after creating an alias in the finder. say i have a folder "foo" in "/Users/me/Documents/foo" and i want to programatically create an alias of that folder on my desktop "/Users/ me/Desktop/fooalias"
how can i do that?
to start with AFAIK i need to create an FSRef for both the paths and then create an alias using FSNewAlias. But if i try to create an FSRef for "/Users/me/Desktop/ fooalias" (which doe snot exist) it gives me error saying "can't get path". I considered using BDAlias ( http://eschatologist.net/bDistributed.com/index.html ), but how can i use it to actually create the alias folder?

Here is my code snippet

// aliasPath:-  path at which to create the alias folder
// targetPath:- the actual path the alias would be referring to

+ (void)createAliasforTargetPath:(NSString *)targetPath aliasPath: (NSString *)aliasPath
{
        FSRef ailasRef;
OSErr err = FSPathMakeRef((const UInt8 *)[aliasPath fileSystemRepresentation], &ailasRef, NULL);
        if(err != noErr)
                NSLog(@"Error creating alias FSRef");
        else
        {
                FSRef targetRef;
err =FSPathMakeRef((const UInt8 *)[targetPath fileSystemRepresentation], &targetRef, NULL);
                if(err != noErr)
                        NSLog(@"Error creating alias's target FSRef");
                else
                {
                        AliasHandle aliasHandle;
                        err = FSNewAlias(&targetRef, &targetRef, &aliasHandle);
                        if(err != noErr)
                                NSLog(@"Error creating alias handler");
                        else
                        {
                                int fd = open([aliasPath UTF8String], O_WRONLY 
| O_CREAT |
                                                          O_TRUNC, S_IRWXU | 
S_IRWXG | S_IRWXO);
                                if(fd == -1)
                                        perror("store-open");
                                else
                                {
                                        HLock((Handle)aliasHandle);
                                        long handleSize = 
GetHandleSize((Handle)aliasHandle);
                                        int wrote = write(fd, &handleSize, 
sizeof(long));
                                        wrote = write(fd, *aliasHandle, 
handleSize);
                                        close(fd);
                                        
                                        HUnlock((Handle)aliasHandle);
                                        
                                        printf("store-wrote file\n");
                                }
                        }
                }
        }
}

I'd appreciate if some one can help me with this,
Thanka,
Chaitanya
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to