【发布时间】:2012-07-22 22:07:55
【问题描述】:
我想获取在 OS X 下使用 Cocoa/Objective-C 可卸载/可弹出的驱动器列表。
我希望 NSWorkspace getFileSystemInfoForPath::::: 能帮助我:
NSArray* listOfMedia = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths];
NSLog(@"%@", listOfMedia);
for (NSString* volumePath in listOfMedia)
{
BOOL isRemovable = NO;
BOOL isWritable = NO;
BOOL isUnmountable = NO;
NSString* description = [NSString string];
NSString* type = [NSString string];
BOOL result = [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:volumePath
isRemovable:&isRemovable
isWritable:&isWritable
isUnmountable:&isUnmountable
description:&description
type:&type];
NSLog(@"Result:%i Volume: %@, Removable:%i, W:%i, Unmountable:%i, Desc:%@, type:%@", result, volumePath, isRemovable, isWritable, isUnmountable, description, type);
}
输出:
...
Result:1 Volume: /Volumes/LR Photos, Removable:0, W:1, Unmountable:0, Desc:hfs, type:hfs
...
“LR Photos”是一个外部驱动器(通过 Thunderbolt 连接),应该是可移动和/或不可安装的(或者,至少我认为应该是)。 :)
我应该以不同的方式解决这个问题吗?
提前致谢!
【问题讨论】:
-
磁盘工具对卷有什么看法?如果您尝试在 Finder 中弹出它会怎样?
-
“LR Photos”驱动器是如何格式化的?
-
感谢您的好评。我真正想做的就是建立一个列表,列出所有连接到机器的驱动器,如果我想这样做,可以被弹出/卸载。现在我通过 Finder 来做,但我想从一个地方做(一个额外的菜单栏等)。我知道 Mac App Store 中有应用程序可以执行此操作,但我想自己编写。 :) 再次感谢!
标签: objective-c macos cocoa osx-lion