Sipho Koza
Sipho Koza

Reputation: 902

How to get a filepath from a directory without file name in iOS Objective c

Good day

How do you get a filePath without fileName from a fullpath. Lets say I have a path:

NSString *myPath = @"/Users/myName/Library/Developer/CoreSimulator/Devices/.../Library/Caches/Getting Started.pdf";

and I want to just have

NSString *newPath = @"/Users/myName/Library/Developer/CoreSimulator/Devices/.../Library/Caches";

I didnt want to substring it, I hope there is a better solution.

Thank you in advance.

Upvotes: 2

Views: 1775

Answers (2)

Milan Vadgama
Milan Vadgama

Reputation: 321

try this code

  NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

    NSLog(@" DocumentPath %@",documentPath);

Upvotes: 1

Avi
Avi

Reputation: 7552

Check the class reference for NSString.

newPath = [path stringByDeletingLastPathComponent];

Upvotes: 8

Related Questions