iOS下载文件一般保存到NSDocumentDirectory内,但是为了更好整理文件内容,那就要自定义的生成一些文件夹,和做一些删除文件夹的操作.
- (NSString *)pathToPatientPhotoFolder { NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *patientPhotoFolder = [documentsDirectory stringByAppendingPathComponent:@"patientPhotoFolder"]; // Create the folder if necessary BOOL isDir = NO; NSFileManager *fileManager = [[NSFileManager alloc] init]; if (![fileManager fileExistsAtPath:patientPhotoFolder isDirectory:&isDir] && isDir == NO) { [fileManager createDirectoryAtPath:patientPhotoFolder withIntermediateDirectories:NO attributes:nil error:nil]; } return patientPhotoFolder; } //删除文件 NSString *patientPhotoFolder = [[NSFileManager defaultManager] pathToPatientPhotoDirectory]; NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:patientPhotoFolder error:nil]; for (NSString *filename in contents) { [[NSFileManager defaultManager] removeItemAtPath:[patientPhotoFolder stringByAppendingPathComponent:filename] error:NULL]; }
原文地址:http://stackoverflow.com/questions/13837993/how-can-i-make-a-folder-in-nsdocument-directory-where-i-can-save-all-the-photos
时间: 2024-10-09 06:31:40