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

contentsEqualAtPath:andPath:

ファイルやフォルダの中身を比較して結果を返します


-(BOOL) contentsEqualAtPath:(NSString *)path1
   andPath:(NSString *)path2


【返り値】
   BOOLYES/NO
【パラメータ】
   path1パス
   path2パス


【解説】

ファイルやフォルダの中身を比較して結果を返します。
path1とpath2のファイルの内容を比較して結果を返します。
同じであればYESを返します。
path1とpath2がディレクトリ(フォルダ)の場合は、含まれているファイルのリストを比較します。



【例文】


#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];
[myFile createFileAtPath:@"createdNewFile2" contents:dat1 attributes:dic];
//ファイル比較
if ([myFile contentsEqualAtPath:@"createdNewFile" andPath:@"createdNewFile2"]){
NSLog(@"YES");
}else{
NSLog(@"NO");
}


}

@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