luvieere
luvieere

Reputation: 37494

Split File Path into Components in iPhone SDK

Is there a framework or a library that I could use to split a file path into its components in iPhone SDK? I know I could code it myself, but I don't want to reinvent the wheel.

Upvotes: 5

Views: 3664

Answers (4)

P i
P i

Reputation: 30684

pathForResource? without using extension (Iphone)

One of the answers to this question provides the necessary code. Just the question is badly formulated.

Upvotes: 0

Ole Begemann
Ole Begemann

Reputation: 135548

-[NSString pathComponents] is made exactly for this.

Upvotes: 14

Tim
Tim

Reputation: 60130

You can probably just split at the character /; the relevant documentation says that "NSString represents paths generically with ‘/’ as the path separator and ‘.’ as the extension separator." So a simple

NSArray *components = [pathString componentsSeparatedByString:@"/"];

should suffice.

Upvotes: 0

Jorge Israel Peña
Jorge Israel Peña

Reputation: 38586

I'm not completely sure, but NSFileManager's -subpathsAtPath method sounds like what you want to do. It splits up the components of a path into an NSArray.

EDIT: Actually, I might have misunderstood the documentation. Sorry if that's the case.

Upvotes: 0

Related Questions