getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:
指定したファイルのあるデバイスの属性を返します
- (BOOL)getFileSystemInfoForPath:(NSString *)fullPath isRemovable:(BOOL *)removableFlag isWritable:(BOOL *)writableFlag isUnmountable:(BOOL *)unmountableFlag description:(NSString **)description type:(NSString **)fileSystemTypefunc 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(NSString *)fullPath_ fullPath: String
取り外しできるか
Objective-C(BOOL *)removableFlag
removableFlag: UnsafeMutablePointer<ObjCBool>
書き込みできるか
Objective-C(BOOL *)writableFlag
writableFlag: UnsafeMutablePointer<ObjCBool>
アンマウントできるか
Objective-C(BOOL *)unmountableFlag
unmountableFlag: UnsafeMutablePointer<ObjCBool>
詳細
Objective-C(NSString **)descriptiondescription: AutoreleasingUnsafeMutablePointer<NSString?>
(NSString **)fileSystemTypefileSystemType: AutoreleasingUnsafeMutablePointer<NSString?>)
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0
更新時のバージョン
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
//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 }