3

这是我的代码:

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]);
}

但输出类似于file://localhost/Volumes/....

如何获取所选文件的基本名称(例如 Cat.jpg)?

4

2 回答 2

3
NSURL *url = ...;
NSString *filename = [[url path] lastPathComponent];
于 2012-06-17T15:36:13.593 回答
3

在这种情况下,只需要没有任何扩展名的文件名:

NSString *fileName = [[path lastPathComponent] stringByDeletingPathExtension];
于 2015-07-04T03:47:31.990 回答