繁体   English   中英

如何使用NSOpenPanel获取文件名而不是完整目录?

[英]How to get just the file name, not the full directory, with NSOpenPanel?

这是我的代码:

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

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

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

NSString *fileName = [[path lastPathComponent] stringByDeletingPathExtension];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM