---
title: "遍历目录下指定文件类型的文件，并输出"
author: "helmsman_xcode"
date: "2011-08-17T17:54:46Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2011-08-17T17:54:46Z"
id: 1151639
url: "https://helmsman-xcode.iteye.com/blog/1151639"
---

```Ios
 
  [super viewdidload];
    NSFileManager *fileManager = [nsfilemanager defaultmanager];
    NSArray *path =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *file = [path objectatindex:0]; //获得Document系统文件目录路径
    NSDirectoryEnumerator *direnum = [filemanager enumeratoratpath:file ]; //遍历目录
//    NSMutableArray *files = [nsmutablearray arraywithcapacity:50];
    NSMutableArray *files = [[nsmutablearray alloc] init]; 
    NSString *fileName;
    while((fileName = [direnum nextobject])){
        if([[filename pathextension] isEqualToString:@"png"]){  //遍历条件
            [files addobject:filename];
            NSLog(@"%@",fileName);
        }
    }

```