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;

}

 

 

 
 
posted @ 2015-05-06 22:27  汤冉阳  阅读(581)  评论(0编辑  收藏  举报