#import"ViewController.h"
@interfaceViewController ()
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//得到文件管理器
NSFileManager *fm = [NSFileManagerdefaultManager];
// 复制
[fmcopyItemAtPath:@"/Users/ivan/Desktop/a.png"toPath:@"/Users/ivan/Desktop/copy/a.png"error:nil];
// 移动 移动的时候目的地不能有重名的
[fmmoveItemAtPath:@"/Users/ivan/Desktop/a.png"toPath:@"/Users/ivan/Desktop/copy/a.png"error:nil];
// 删除
NSError *err =nil;
[fmremoveItemAtPath:@"/Users/ivan/Desktop/copy/a.png"error:&err];
if (err) {
NSLog(@"出错了");
}
// 创建文件夹
[fmcreateDirectoryAtPath:@"/Users/ivan/Desktop/a/b/c/d/e/f"withIntermediateDirectories:YESattributes:nilerror:nil];
// 判断文件是否存在
if ([fm fileExistsAtPath:@"/Users/ivan/Desktop/lany.txt"]) {
NSLog(@"文件存在");
}
// 判断文件是否存在是否是文件夹
BOOL isDir =NO;
if ([fmfileExistsAtPath:@"/Users/ivan/Desktop/桌面.zip"isDirectory:&isDir]){
NSLog(@"存在");
if (isDir) {
NSLog(@"是文件夹");
}else{
NSLog(@"不是文件夹");
}
}else{
NSLog(@"不存在");
}
// 获取文件夹里面所有的内容
NSArray *fileNames = [fmcontentsOfDirectoryAtPath:@"/Users/gj/Desktop/"error:nil];
for (NSString *fileNamein fileNames) {
NSLog(@"%@",fileName);
}
}
@end