objective-c 遍历文件夹及判断文件类型
// // main.m // FileSearchTest // // Created by Zhang Leonardo on 11-10-31. // Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
// To discuss via :www.renren.com/leonardozhang //
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool { NSFileManager *manager = [NSFileManager defaultManager]; NSString *home = [@"/Users/zhangchenlong/test" stringByExpandingTildeInPath]; NSLog(@"home: %@", home); NSDirectoryEnumerator *direnum = [manager enumeratorAtPath:home]; NSMutableArray *files = [NSMutableArray arrayWithCapacity:42]; NSString *filename ; while (filename = [direnum nextObject]) { if ([[filename pathExtension] isEqualTo:@"jpg"]) { [files addObject: filename]; } } NSEnumerator *fileenum; fileenum = [files objectEnumerator]; while (filename = [fileenum nextObject]) { NSLog(@"%@", filename); } } return 0; }
|
请发表评论