转载请标注来自:http://blog.csdn.net/u014202635/article/details/46863629
1.
选Devices
2.
3.
选中第二行
4.
保存在桌面
5.
右击选中显示包内容
6.
以上环境为x-code6.3.1
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//图片批量存储获取删除
#import <Foundation/Foundation.h>
@interface ImageSaveHelper :NSObject
/**
* 将图片数组以arrayName存储
*
* @param array 图片数组,数组元素是UIImage
* @param arrayName 存储图片文件名称
*/
+(void)saveImageArray:(NSMutableArray *)array andArrayName:(NSString *)fileName;
/**
* 获取arrayName文件夹下所有图片
*
* @param arrayName 文件名称
*
* @return 返回元素UIImage组成的数组
*/
+(NSMutableArray *)getImageArrayWithName:(NSString *)fileName;
/**
* 删除fileName文件夹下名称为imageName的文件
*
* @param imageName image名称
* @param fileName 文件夹名称
*
* @return 是否删除成功
*/
+(BOOL)deleteImageName:(NSString * )imageName withFileName:(NSString *)fileName;
@end
#import "ImageSaveHelper.h"
#import <UIKit/UIKit.h>
@implementation ImageSaveHelper
+(void)saveImageArray:(NSMutableArray *)array andArrayName:(NSString *)fileName{
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * path = [paths[0]stringByAppendingPathComponent:fileName];
if (![[NSFileManagerdefaultManager]fileExistsAtPath:path]){//判断createPath路径文件夹是否已存在,此处createPath为需要新建的文件夹的绝对路径
[[NSFileManagerdefaultManager] createDirectoryAtPath:pathwithIntermediateDirectories:YESattributes:nilerror:nil];//创建文件夹
}
for (int i =0 ; i < array.count; i++) {
NSString *filePath = [path stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@%d.png",fileName, i]]; // 保存文件的名称
[UIImagePNGRepresentation(array[i])writeToFile: filePath atomically:YES];
}
}
+(NSMutableArray *)getImageArrayWithName:(NSString *)fileName{
NSMutableArray * imageArray = [NSMutableArrayarray];
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * path = [paths[0]stringByAppendingPathComponent:fileName];
if (![[NSFileManagerdefaultManager]fileExistsAtPath:path]){//判断createPath路径文件夹是否已存在,不存在直接返回
return imageArray;
}
//此文件夹下所有图片名称
NSArray *filesNameArray = [[NSFileManagerdefaultManager] subpathsOfDirectoryAtPath:patherror:nil];
if (filesNameArray && filesNameArray.count !=0 ) {
for (int i =0 ; i < filesNameArray.count; i++) {
UIImage * image = [UIImageimageWithContentsOfFile:[path stringByAppendingPathComponent:filesNameArray[i]]];
[imageArrayaddObject:image];
}
}
return imageArray;
}
+(BOOL)deleteImageName:(NSString * )imageName withFileName:(NSString *)fileName;
{
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * path = [paths[0]stringByAppendingPathComponent:fileName];
NSString * pathFull = [pathstringByAppendingPathComponent:[NSStringstringWithFormat:@"%@.png",imageName]];
if([[NSFileManagerdefaultManager] fileExistsAtPath:pathFull])//如果存在临时文件的配置文件
{
return [[NSFileManagerdefaultManager] removeItemAtPath:pathFullerror:nil];
}
return NO;
}
@end