Amy*_*Amy 14 c++ macos qt objective-c
我不是非常精通Mac OS X编程,但我正在开发一个需要有关存储设备信息的Qt应用程序.基本上是硬盘驱动器和USB拇指驱动器的列表.最终结果应该像一个向量,其中包含每个设备的以下信息:
string:标签
字符串:挂载点
字符串:设备描述(又名友好名称)
uint64:大小
bool:可移动吗?
我一直在Windows上和以下帖子中获取有关磁盘驱动器结果的信息在windows7 - 32位系统上提供了很大的帮助.但是,虽然我非常精通C/C++,但我在Mac OS X编程,Cocoa和/或Objective-C方面并不是很好,所以任何帮助都会非常感激.
Geo*_*che 14
这应该可以帮助您获得所需的大部分内容:
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);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4502 次 |
最近记录: |