| Home 目次>Foundation>NSFileManager このサイトはこちらに移転しました。 | |
createFileAtPath:contents:attributes:
内容データで名前と属性を指定してファイルを作ります
-(BOOL) createFileAtPath:(NSString *)path
contents:(NSData *)contents
attributes:(NSDictionary *)attributes
【返り値】 | |
| BOOL | YES/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
![]() | |
この記事を評価してください。
| Home 目次>Foundation>NSFileManager | 修正日2006.12.26 |