#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);