macos - 如何从 NSURL 获取路径/目录组件?

标签 macos cocoa nsurl

我从 NSSavePanel 检索了 NSURL。我现在有了这个 NSURL,它给了我以下内容:

文件://localhost/Users/brett/Documents/asdf%20asdf.json

现在,我可以轻松地使用如下所示的内容来检索文件名:

[[[NSFileManager defaultManager] displayNameAtPath:pathAndFilename] stringByDeletingPathExtension]

这给了我本地化的文件名,正如预期的那样:asdf%20asdf

那么,如何获取路径,如下所示: file://localhost/Users/brett/Documents/

最佳答案

-[NSURL URLByDeletingLastPathComponent] 是实现此目的的最简单方法。

关于macos - 如何从 NSURL 获取路径/目录组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12719303/

相关文章:

ios - SMS WatchKit 多个数字分隔符

python - 在 Mac OS 下查找事件的 IPv6 接口(interface)(使用 Python)

ios - 如何定义全局结构?

c - MAC OS X : zsh: no such file or directory once running a program from Codeblocks

xcode - git(osis) 和 Xcode

objective-c - maskToBounds 设置为 NO 似乎没有效果

cocoa - 自定义 "NSView"为 "NSCollectionViewItem": How to get or access collection item or its data from its view to perform a custom draw?

objective-c - 对象 : strong property with NSString

ios - AFNetworking UIImage NSURL

iphone - 验证电话提示后是否进行了调用