Fwd: C: treated as a path component
Fwd: C: treated as a path component
- Subject: Fwd: C: treated as a path component
- From: "Jeremy W. Sherman" <email@hidden>
- Date: Thu, 16 Apr 2009 00:03:18 -0400
You could also use basename(3) instead of Cocoa/CF calls. Since it
could modify the passed-in string, you'll need to either use
-[NSString getFileSystemRepresentation:maxLength:] or copy the string
returned by -[NSString fileSystemRepresentation]. Of course, if you're
worried about the path separator being something other than /, you
probably aren't going to be able to use something line basename(3).
You could retrieve the path in POSIX format using
CFURLCopyFileSystemPath (CFURL is toll-free bridged with NSURL, as is
CFString with NSString) and passing in kCFURLPOSIXPathStyle.
A briefer way to write [array objectAtIndex:([array count] - 1)] is
[array lastObject]. -addObject:/-lastObject together make it really
easy to treat an NSMutableArray as a stack.
—Jeremy
On Wed, Apr 15, 2009 at 10:49 PM, Steve Christensen <email@hidden> wrote:
> On Apr 15, 2009, at 1:34 PM, Jean-Daniel Dupas wrote:
>
>> Le 15 avr. 09 à 01:57, Dragan Milić a écrit :
>>
>>> Hell all,
>>>
>>> Let's suppose I've got NSString @"C:omponent" , which represents the name
>>> of a file. Is there a way to instruct NSString class not to treat a leading
>>> single letter followed by a column as a path separator? Namely, I need this
>>> one treated as only one path component @"C:omponent", but NSString sees two,
>>> @"C:" and "omponent". So, if I ask for the last path component, I get
>>> @"omponent" instead of the whole string @"C:omponent".
>>>
>>> I've searched documentation, took a look into NSPathUtilities.h, but no
>>> help.
>>
>>
>> You can use the CFURL API which provide a set of function to manipulate
>> path, but due to memory management, it's not as clean than the Cocoa string
>> API (objects are not autoreleased).
>>
>> • CFURLCreateCopyAppendingPathComponent
>> • CFURLCreateCopyAppendingPathExtension
>> • CFURLCreateCopyDeletingLastPathComponent
>> • CFURLCreateCopyDeletingPathExtension
>>
>> CFURLCopyPathExtension
>> CFURLCopyLastPathComponent
>>
>> etc…
>
> Or to stay entirely in Cocoa-land, you could always use
>
> NSArray* components = [filePath componentsSeparatedByString:@"/"];
> NSString* lastPathComponent = [components objectAtIndex:([components count]
> - 1)];
>
> Not quite as straightforward as the methods in NSPathUtilities but it would
> certainly work around the colon issue...
>
> _______________________________________________
>
> 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
>
_______________________________________________
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