宏定义
#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]]; //存到数组
}
}
本文介绍如何使用Swift编程语言结合Foundation框架中的类来读取iOS设备Documents目录下的所有MP3文件,并将这些文件名存储到NSMutableArray中。具体实现包括获取Documents路径、列举目录下所有文件以及筛选出特定格式的文件。

7281

被折叠的 条评论
为什么被折叠?



