On Sat, Apr 25, 2009 at 6:33 PM, Erg Consultant
<erg_consult...@yahoo.com> wrote:
> I am trying to convert an NSString containing a path to a file directly to an 
> FSRef. If there are no special characters in the path, it's easy - I can go 
> from NSString to CFURL to FSRef.
>
> But if the path contains any special characters at all, both CFURL and NSURL 
> creation routines fail. No matter what I do, or which routines I use, it 
> won't work.
>
> Unfortunately I am stuck with some 3rd party apps that have special 
> characters like (tm) in their bundle names and I can't change them.
>
> Isn't there some easy way to get an FSRef from an NSString that is a path 
> containing special characters?

Works for me. My suspicion is that you aren't properly creating your
NSString in the first place.

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    if (argc != 2) {
        NSLog( @"usage: <file/directory path>" );
        [pool drain];
        return 1;
    }

    NSString *filePath = [NSString stringWithCString:argv[ 1 ]
encoding:NSUTF8StringEncoding];
    NSLog( @"filePath = %@", filePath );

    NSURL *fileURL = [NSURL fileURLWithPath:filePath];
    NSLog( @"fileURL = %@", [fileURL absoluteURL] );

    FSRef fileFSRef;
    if (CFURLGetFSRef( (CFURLRef)fileURL, &fileFSRef )) {
        NSLog( @"Created FSRef!" );
    } else {
        NSLog( @"Failed to create FSRef." );
    }

    [pool drain];
    return 0;
}
_______________________________________________

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 arch...@mail-archive.com

Reply via email to