macOS/iOS API解説

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

目次

createDirectoryAtPath:attributes:

属性を指定して空のディレクトリ(フォルダ)を作ります
-(BOOL)createDirectoryAtPath:(NSString *)path:
             attributes:(NSDictionary *)attributes:

解説

属性を指定して空のディレクトリ(フォルダ)を作ります。
作ることができればYESを返します。
できなければNOを返します。
同じ名前のディレクトリ(フォルダ)がある場合は作られない。
親ディレクトリ(フォルダ)がない場合は作られない。
【attributes】ディレクトリ(フォルダ)の属性
キー 値タイプ
●NSFileOwnerAccountName 所有者名(NSString)
●NSFileGroupOwnerAccountName グループ名(NSString)
● NSFileModificationDate ファイル修正日(NSDate)
● NSFilePosixPermissions POSIXのファイル属性(読み込み・書き込みなど)(NSNumber)
● NSFileExtensionHidden 拡張子を隠すか(BOOLのNSNumber)
● NSFileHFSCreatorCode クリエータタイプ(unsigned longのNSNumber)
● NSFileHFSTypeCode ファイルタイプ(unsigned longのNSNumber)

返り値

( BOOL )

YES/NO

引数

( NSString * )path

パス

( NSDictionary * )attributes

属性の辞書

クラス

NSFileManager

Instance Methods

使用可能

10.0

参照

- changeCurrentDirectoryPath:
- changeFileAttributes:atPath:
- createFileAtPath:contents:attributes:
- currentDirectoryPath

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSString *str = @"~/";
NSFileManager *myFile = [ NSFileManager defaultManager];
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
            [NSDate date],NSFileModificationDate,
            @"owner",@"NSFileOwnerAccountName",
            @"group",@"NSFileGroupOwnerAccountName",
            nil,@"NSFilePosixPermissions",
            [NSNumber numberWithBool:YES],@"NSFileExtensionHidden",
            nil];

[myFile changeCurrentDirectoryPath:[str stringByExpandingTildeInPath]];
[myFile createDirectoryAtPath:@"newFolder" attributes:dic];

NSLog([myFile currentDirectoryPath]);
}

@end