#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject]
//Caches路径
// Do any additional setup after loading the view.
//管理文件的一个类
//单例类
//可以对文件进行 创建 移动 复制 删除
[selfcreateFile];
[selfmoveFile];
[selfcopyFile];
[selfdeleteFile];
[selfisExecutable];
}
- (void)createFile
{
//获取要创建文件夹的路径
NSString *path = [kDocumentPathstringByAppendingPathComponent:@"/DownLoad"];
NSLog(@"%@",path);
//创建文件管理器
//withIntermediateDirectories
//是否复制之前的文件如果写NO就是不覆盖
//不覆盖即创建文件夹失败
NSFileManager*fileManager = [NSFileManagerdefaultManager];
BOOL isCreate = [fileManagercreateDirectoryAtPath:pathwithIntermediateDirectories:YESattributes:nilerror:nil];
NSLog(@"%d",isCreate);
}
- (void)moveFile
{
//获取原路径
NSString *oldPath = [kDocumentPathstringByAppendingPathComponent:@"/DownLoad"];
//获取新路径
NSString *newPath = [kCachePathstringByAppendingPathComponent:@"/DownLoad"];
NSLog(@"%@",oldPath);
//创建文件管理器管理对象
NSFileManager *manager = [NSFileManager defaultManager];
//移动文件夹(从老的移动到新的路径)
BOOL isMove = [manager moveItemAtPath:oldPath toPath:newPath error:nil];
NSLog(@"%d",isMove);
}
- (void)copyFile
{
//获取原路径
NSString *oldPath = [kCachePathstringByAppendingPathComponent:@"/DownLoad"];
//获取新路径
NSString *newPath = [kDocumentPathstringByAppendingPathComponent:@"/DownLoad"];
NSLog(@"%@",oldPath);
NSLog(@"%@",newPath);
NSFileManager *manager = [NSFileManagerdefaultManager];
//拷贝
BOOL isCopy = [manager copyItemAtPath:oldPathtoPath:newPatherror:nil];
NSLog(@"%d",isCopy);
}
- (void)deleteFile
{
//获取要删除的路径
NSString *path = [kDocumentPathstringByAppendingPathComponent:@"/DownLoad"];
//创建文件管理对象
NSFileManager *manager = [NSFileManagerdefaultManager];
//删除
BOOL isRemove = [manager removeItemAtPath:patherror:nil];
}
- (void)isExecutable
{
//获取要判断的路径
NSString *path = [kCachePathstringByAppendingPathComponent:@"/DownLoad"];
//创建文件管理对象
NSFileManager *manager = [NSFileManagerdefaultManager];
//判断是否存在
BOOL isExecutable = [manager isExecutableFileAtPath:path];
NSLog(@"%d",isExecutable);