我不是很精通Mac OS X编程,但是我正在研究Qt应用程序,该应用程序需要有关存储设备的信息。基本上是硬盘驱动器和USB拇指驱动器的列表。
最终结果应该像一个 vector ,其中包含每个设备的以下信息:
字符串:标签
字符串:安装点
字符串:设备描述(又名友好名称)
uint64:大小
bool :可移动吗?
我一直在Windows上进行此操作,以下Get information about disk drives result on windows7 - 32 bit system帖子对您有很大帮助。但是,尽管我非常精通C/C++,但在Mac OS X编程,Cocoa和/或Objective-C方面却不是很出色,因此任何帮助将不胜感激。
最佳答案
这应该为您提供大部分所需的东西:
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSArray *vols = [ws mountedLocalVolumePaths];
NSFileManager *fm = [NSFileManager defaultManager];
for (NSString *path in vols)
{
NSDictionary* fsAttributes;
NSString *description, *type, *name;
BOOL removable, writable, unmountable, res;
NSNumber *size;
res = [ws getFileSystemInfoForPath:path
isRemovable:&removable
isWritable:&writable
isUnmountable:&unmountable
description:&description
type:&type];
if (!res) continue;
fsAttributes = [fm fileSystemAttributesAtPath:path];
name = [fm displayNameAtPath:path];
size = [fsAttributes objectForKey:NSFileSystemSize];
NSLog(@"path=%@\nname=%@\nremovable=%d\nwritable=%d\nunmountable=%d\n"
"description=%@\ntype=%@, size=%@\n\n",
path, name, removable, writable, unmountable, description, type, size);
}