1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// IBTFileManager.m
// XFFruit
//
// Created by Xummer on 15/6/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "IBTFileManager.h"
@implementation IBTFileManager
// File Size
+ (NSNumber *)sizeForFileAtPath:(NSString *)filePath {
NSError *attributesError;
NSDictionary *fileAttributes =
[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&attributesError];
if (!attributesError) {
return fileAttributes[ NSFileSize ] ? : @(0);
}
else {
return @(0);
}
}
+ (BOOL)removeFileAtPath:(NSString *)filePath {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if ([fileManager fileExistsAtPath:filePath]) {
[fileManager removeItemAtPath:filePath error:&error];
}
else {
return YES;
}
if (error) {
CLog(@"%@",error);
return NO;
}
else{
return YES;
}
}
+ (BOOL)removeFileAtUrl:(NSURL *)filePathUrl {
if (!filePathUrl ) {
return NO;
}
NSString *filePathStr = [filePathUrl path];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if ([fileManager fileExistsAtPath:filePathStr]) {
[fileManager removeItemAtURL:filePathUrl error:&error];
}
else {
return YES;
}
if (error) {
CLog(@"%@",error);
return NO;
}
else{
return YES;
}
}
+ (BOOL)moveFile:(NSURL *)fromPath toPath:(NSURL *)toPath
{
if (!toPath || !fromPath) {
return NO;
}
NSString *fromPathStr = [fromPath path];
NSString *toPathStr = [toPath path];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
if ([fileManager fileExistsAtPath:fromPathStr]) {
[fileManager moveItemAtPath:fromPathStr toPath:toPathStr error:&error];
}
if (error) {
CLog(@"%@",error);
return NO;
}
else{
return YES;
}
}
@end