macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:

INDEX>AppKit>NSWorkspace

指定したファイルのあるデバイスの属性を返します

Objective-C

- (BOOL)getFileSystemInfoForPath:(NSString *)fullPath
                     isRemovable:(BOOL *)removableFlag
                      isWritable:(BOOL *)writableFlag
                   isUnmountable:(BOOL *)unmountableFlag
                     description:(NSString **)description
                            type:(NSString **)fileSystemType

Swift

func getFileSystemInfoForPath(_ fullPath: String,
                  isRemovable removableFlag: UnsafeMutablePointer<ObjCBool>,
                   isWritable writableFlag: UnsafeMutablePointer<ObjCBool>,
                isUnmountable unmountableFlag: UnsafeMutablePointer<ObjCBool>,
                  description description: AutoreleasingUnsafeMutablePointer<NSString?>,
                         type fileSystemType: AutoreleasingUnsafeMutablePointer<NSString?>) -> Bool

解説

指定したファイルのあるデバイスの属性を返します。

返り値

Objective-C

BOOL

Swift

Bool

マウントできるYES/NO

引数

フルパス
Objective-C

(NSString *)fullPath

Swift

_ fullPath: String

取り外しできるか
Objective-C

(BOOL *)removableFlag

Swift

removableFlag: UnsafeMutablePointer<ObjCBool>

書き込みできるか
Objective-C

(BOOL *)writableFlag

Swift

writableFlag: UnsafeMutablePointer<ObjCBool>

アンマウントできるか
Objective-C

(BOOL *)unmountableFlag

Swift

unmountableFlag: UnsafeMutablePointer<ObjCBool>

詳細
Objective-C

(NSString **)description

Swift

description: AutoreleasingUnsafeMutablePointer<NSString?>

ファイルシステムタイプ
Objective-C

(NSString **)fileSystemType

Swift

fileSystemType: AutoreleasingUnsafeMutablePointer<NSString?>)

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.0

参照

cocoaapi.hatenablog.com

更新時のバージョン

OS X 10.10.3
Swift1.2

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{

 //開けるファイル拡張子の配列
    NSArray      *fileTypes    = [ NSArray arrayWithObject : @"tiff" ];
    //OpenPanelを作る
    NSOpenPanel  *opPanel       = [ NSOpenPanel openPanel ];

    //OpenPanelの結果のボタン番号
    int		  opRet;
    BOOL	openResult;
    NSString *fileType,*description;
    BOOL removable,writable,unmountable; 
        //OpenPanelでファイル選択   
    opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Pictures" //どのどのファイルを選択しておくか
                                    types : fileTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
    
        openResult = [[NSWorkspace sharedWorkspace] 
                        getFileSystemInfoForPath:[ opPanel filename ] 
                            isRemovable:&removable
                            isWritable:&writable
                            isUnmountable:&unmountable
                            description:&description
                            type:&fileType
                            ];
                           
        NSLog(fileType);
        NSLog(description);
	if (openResult){
		NSLog(@"removable %@ ,writable %@ ,unmountableFlag %@ ",
					(removable)?@"YES":@"NO" ,
					(writable)?@"YES":@"NO" ,
					(unmountable)?@"YES":@"NO" 
					);
	}
	else{
		NSLog(@"NO");
	}
}

}

@end

Swift

    //NSWorkspace getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:
    @IBAction func function025(sender: AnyObject) {
        //ファイルを選択
        var openPanel = NSOpenPanel()
        openPanel.allowsMultipleSelection = false
        openPanel.canChooseDirectories = false
        openPanel.canCreateDirectories = false
        openPanel.canChooseFiles = true
        openPanel.beginWithCompletionHandler { (result) -> Void in
            //オープンパネルでOKを選択したら
            if result == NSFileHandlingPanelOKButton {
                //選択したファイルを
                let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace()
                let theURL : NSURL =  openPanel.URL!
                let filepath : NSString = theURL.path!
                
                var removable = ObjCBool(false)
                var writable = ObjCBool(false)
                var unmountable = ObjCBool(false)
                var description = NSString?()
                var type = NSString?()
                if (theWorkspace.getFileSystemInfoForPath( filepath as! String,
                    isRemovable: &removable,
                    isWritable: &writable,
                    isUnmountable: &unmountable,
                    description: &description,
                    type: &type )
                    ){
                    NSLog("YES")
                }else{
                    NSLog("NO")
                }
                // -> YES
                NSLog("%@,%@", description! ,type!)
                // -> hfs,hfs
                if removable {NSLog("removable:YES")}else{NSLog("removable:NO")}
                // -> removable:NO
                if writable {NSLog("writable:YES")}else{NSLog("writable:NO")}
                // -> writable:YES
                if removable {NSLog("removable:YES")}else{NSLog("removable:NO")}
                // -> removable:NO
                
            }//if result
        }//openPanel.beginWithCompletionHandler
    }