Reputation: 3370
This is my code:
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:YES];
[panel runModal];
NSInteger count = [[panel URLs] count];
for (int i=0; i<count; i++) {
NSLog(@"%@", [[panel URLs] objectAtIndex:i]);
}
But the output is something like file://localhost/Volumes/....
How can I just get the basename of the selected file (e.g Cat.jpg)?
Upvotes: 3
Views: 4091
Reputation: 3524
In the case only filename, without any extension, is needed:
NSString *fileName = [[path lastPathComponent] stringByDeletingPathExtension];
Upvotes: 3
Reputation: 43472
NSURL *url = ...;
NSString *filename = [[url path] lastPathComponent];
Upvotes: 3