objective-c 遍历文件夹查看文件

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
    @autoreleasepool {

NSFileManager *manager = [NSFileManager defaultManager];

//如果是相对相对路径转换为绝对路径

NSString *home = [@"/Users/tang/desktop/123" stringByExpandingTildeInPath];

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

//列举出文件路径下的目录

NSDirectoryEnumerator *direnum = [manager enumeratorAtPath:home];

NSMutableArray *files = [NSMutableArray arrayWithCapacity:42];

NSString *filename ;

while (filename = [direnum nextObject]) {

[files addObject: filename];

// if ([[filename pathExtension] isEqualTo:@"jpg"]) {

//       [files addObject: filename];

//}

}

NSEnumerator *fileenum;

fileenum = [files objectEnumerator];

for (id filePath in fileenum) {

NSLog(@"%@", filePath);

}

  //while (filename = [fileenum nextObject]) {

  //       NSLog(@"%@", filename);

  //}

}

return 0;

}

 
 
上一篇:三大框架之hibernate的反转


下一篇:(hdu)5652 India and China Origins 二分+dfs