Re: Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
Re: Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
- Subject: Re: Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
- From: Ken Thomases <email@hidden>
- Date: Sat, 16 Jan 2010 06:59:29 -0600
What others have suggested are good, but I also wanted to point out something:
On Jan 13, 2010, at 9:30 AM, rohan a wrote:
> Using the new NSURL methods available with Cocoa on Mac OS X 10.6, I am
> trying to create an alias file to a certain file. However, this method
> requires a NSURL data type. But I am writing a C program along with an
> objective-C program to accomplish this. The C program would accept the
> inputs as C strings. I would then convert them to NSString and then to NSURL
> strings. However, this is not working :(
> By hardcoding the NSURL strings the program works fine.
> #import <Foundation/Foundation.h>
>
> int CreateAlias(const char *target, const char *aliasname)
> {
> CFStringRef Ref1 = CFStringCreateWithCString(NULL, target,
> kCFStringEncodingASCII);
>
> CFStringRef Ref2 = CFStringCreateWithCString(NULL, aliasname,
> kCFStringEncodingASCII);
>
> if (Ref1 == NULL || Ref2 == NULL)
> exit(1);
>
> NSString *Destination = (NSString *)Ref1;
> NSString *Alias = (NSString *)Ref2;
> //NSURL *src = [NSURL URLWithString:@"file:///Alias_dir/aliastext"];
> //NSURL *dest = [NSURL URLWithString:@
> "file:///Alias_dir/aliastext.alias"];
>
> NSURL *src = [NSURL URLWithString:Destination];
> NSURL *dest = [NSURL URLWithString:Alias];
Are the strings file paths or URL strings? It's important to recognize that those are not the same things. In your commented-out literals, you are passing file URL strings, which is appropriate. However, if target and aliasname (and thus Ref1 and Ref2) are not file URL strings but file paths, then you should be creating the NSURL objects with +fileURLWithPath: rather than +URLWithString:. (And, no, prepending "file://" to a file path does not make it a valid file URL string. For example, file paths may have spaces in them, while that's not allowed for URL strings.)
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden