문제

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)?

도움이 되었습니까?

해결책

NSURL *url = ...;
NSString *filename = [[url path] lastPathComponent];

다른 팁

In the case only filename, without any extension, is needed:

NSString *fileName = [[path lastPathComponent] stringByDeletingPathExtension];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top