NSFileManager:createFileAtPath:contents:attributes:
Home 目次>Foundation>NSFileManager このサイトはこちらに移転しました。

createFileAtPath:contents:attributes:

内容データで名前と属性を指定してファイルを作ります


-(BOOL) createFileAtPath:(NSString *)path
   contents:(NSData *)contents
   attributes:(NSDictionary *)attributes


【返り値】
   BOOLYES/NO
【パラメータ】
   pathパス
   contents内容
   attributes属性の辞書


【解説】

内容データで名前と属性を指定してファイルを作ります。



【例文】


#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];
NSString *str2 = @"Mutable data";
NSMutableData *dat1 = [[[NSMutableData alloc] autorelease] initWithCapacity:1];
[dat1 appendBytes:[str2 cString] length:[str2 cStringLength]];


[myFile changeCurrentDirectoryPath:[str stringByExpandingTildeInPath]];
[myFile createFileAtPath:@"createdNewFile" contents:dat1 attributes:dic];


NSLog([myFile currentDirectoryPath]);
}

@end


(C) 2000-2009 Satoshi Oomori.
[Apple]

Google
Webwww.oomori.com
Apple_Store_40x120

[ad:Usual day in Japan]

この記事を評価してください。 

良い 

間違いがある 説明がわかりにくい 例文がわかりにくい  

Home 目次>Foundation>NSFileManager
修正日2006.12.26