天天看点

获取Documents目录下的文件,将相同后缀的文件放到同一数组中

宏定义

#define FILEPATH [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

NSFileManager * fileManager = [NSFileManager defaultManager];

    NSArray * tempFileList = [[NSArray alloc] initWithArray:[fileManager contentsOfDirectoryAtPath:FILEPATH error:nil]];

//    NSLog(@"%@", tempFileList); 打印Documents文件夹下的文件

    NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];

    for (int i = 0; i < tempFileList.count; i++) { 

//遍历Documents目录      

        if ([[tempFileList[i] pathExtension] isEqualToString:@"mp3"]) {  

//取得后缀名这.MP3的文件名      

            [array addObject:tempFileList[i]];  //存到数组

        }

    }