相关疑难解决方法(0)

使用Cocoa获取可卸载驱动器的列表

我想获得在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);
}
Run Code Online (Sandbox Code Playgroud)

输出:

...
Result:1 Volume: /Volumes/LR Photos, Removable:0, W:1, Unmountable:0, Desc:hfs, …
Run Code Online (Sandbox Code Playgroud)

macos cocoa objective-c osx-lion

4
推荐指数
1
解决办法
2885
查看次数

标签 统计

cocoa ×1

macos ×1

objective-c ×1

osx-lion ×1