objective-c 遍历文件夹及判断文件类型

86771895 2011-11-05

objective-c 遍历文件夹及判断文件类型

//

//main.m

//FileSearchTest

//

//CreatedbyZhangLeonardoon11-10-31.

//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.

//  To discuss via :www.renren.com/leonardozhang

//

#import<Foundation/Foundation.h>

intmain(intargc,constchar*argv[])

{

@autoreleasepool{

NSFileManager*manager=[NSFileManagerdefaultManager];

NSString*home=[@"/Users/zhangchenlong/test"stringByExpandingTildeInPath];

NSLog(@"home:%@",home);

NSDirectoryEnumerator*direnum=[managerenumeratorAtPath:home];

NSMutableArray*files=[NSMutableArrayarrayWithCapacity:42];

NSString*filename;

while(filename=[direnumnextObject]){

if([[filenamepathExtension]isEqualTo:@"jpg"]){

[filesaddObject:filename];

}

}

NSEnumerator*fileenum;

fileenum=[filesobjectEnumerator];

while(filename=[fileenumnextObject]){

NSLog(@"%@",filename);

}

}

return0;

}

相关推荐