-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbFileUtils.m
More file actions
55 lines (45 loc) · 1.2 KB
/
DbFileUtils.m
File metadata and controls
55 lines (45 loc) · 1.2 KB
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
//
// FileUtils.m
// DbBridge
//
// Created by John Huang on 3/19/14.
// Copyright (c) 2014 John Huang. All rights reserved.
//
#import "DbFileUtils.h"
#import <sys/xattr.h>
@implementation DbFileUtils
+ (bool)fileExists:(NSString *)path
{
BOOL isDir = NO;
return [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
}
+ (void)deleteFile:(NSString *)path
{
NSError * error = nil;
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
}
+ (bool)copyFile:(NSString *)toPath from:(NSString *)fromPath
{
return [self copyFile:toPath from:fromPath forced:false];
}
+ (bool)copyFile:(NSString *)toPath from:(NSString *)fromPath forced:(bool)forced
{
if (forced)
{
[self deleteFile:toPath];
}
if ([self fileExists:fromPath] && ![self fileExists:toPath])
{
return [[NSFileManager defaultManager] copyItemAtPath:fromPath toPath:toPath error:nil];
}
return false;
}
+ (bool)moveFile:(NSString *)toPath from:(NSString *)fromPath
{
if ([self fileExists:fromPath] && ![self fileExists:toPath])
{
return [[NSFileManager defaultManager] copyItemAtPath:fromPath toPath:toPath error:nil];
}
return false;
}
@end