iOS中判断一个文件夹是否存在
#define DOCUMENTS_FOLDER_AUDIO @"" //你定义的audio对应的文件目录 #define DOCUMENTS_FOLDER_VEDIO @"" //你定义的vedio对应的文件目录 - (void)createFileDirectories { // 判断存放音频、视频的文件夹是否存在,不存在则创建对应文件夹 NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL isDir = FALSE; BOOL isDirExist = [fileManager fileExistsAtPath:DOCUMENTS_FOLDER_AUDIO isDirectory:&isDir]; if(!(isDirExist && isDir)) { BOOL bCreateDir = [fileManager createDirectoryAtPath:DOCUMENTS_FOLDER_AUDIO withIntermediateDirectories:YES attributes:nil error:nil]; if(!bCreateDir){ NSLog(@"Create Audio Directory Failed."); } NSLog(@"%@",DOCUMENTS_FOLDER_AUDIO); } isDir = FALSE; isDirExist = [fileManager fileExistsAtPath:DOCUMENTS_FOLDER_VEDIO isDirectory:&isDir]; if(!(isDirExist && isDir)){ BOOL bCreateDir = [fileManager createDirectoryAtPath:DOCUMENTS_FOLDER_VEDIO withIntermediateDirectories:YES attributes:nil error:nil]; if(!bCreateDir){ NSLog(@"Create Audio Directory Failed."); } NSLog(@"%@",DOCUMENTS_FOLDER_VEDIO); } }