如何通过使用本地url获取卷名称(标签)? [英] how to get the volume name (label) by using a local url?
本文介绍了如何通过使用本地url获取卷名称(标签)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看过NSWorkSpace和NSFileManager,但我找不到我正在寻找的方法。
I have looked at NSWorkSpace and NSFileManager but I can't find out the methods that I'm looking for.
我有一个保存的URL(从NSSavePanel )。
I have a saved url (getting from NSSavePanel).
ie。这个网址可以是/ Users / Josh / Some Folders / file.txt或
/ Volumes /我的USB密钥名称/ file.txt
ie. this url can be /Users/Josh/Some Folders/file.txt or /Volumes/My USB Key Name/file.txt
这个url找出显示的卷名?
So can I use this url to find out the displayed volume name?
[[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]
可以列出所有本地卷名称,但它已在OS x 10.7中弃用
[[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]
can list all the local volume name, but it's Deprecated in os x 10.7
推荐答案
找到答案:
NSURL *savedPath = [NSURL fileURLWithPath:[saveURL.path stringByDeletingLastPathComponent]];
NSError *error;
NSString *volumeName;
[savedPath getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&error];
NSLog(@"volume name: %@ url: %@", volumeName, savedPath);
这篇关于如何通过使用本地url获取卷名称(标签)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文