文件管理 (创建,移动,删除,复制)
2016-12-19 14:19 supper_Ho 阅读(316) 评论(0) 编辑 收藏 举报//
// main.m
// 04-管理目录
//
// Created by apple on 14-3-21.
// Copyright (c) 2014年 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
/*
//1创建目录
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * path = @"/Users/aplle/Desktop/myfolder/aaa";
NSError * error;
//withIntermediateDirectories YES 逐级创建文件夹,NO表示只能够创建一级目录
BOOL isCreateSuccess = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
if (isCreateSuccess)
{
NSLog(@"创建成功");
}
else
{
NSLog(@"error %@",error);
}
*/
//2 移动目录 移动就是剪切操作
/*
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * path = @"/Users/aplle/Desktop/myfolder";
NSString * pathTo = @"/Users/aplle/Desktop/newmyfolder";
NSError * error ;
BOOL isMoveSuccess = [fileManager moveItemAtPath:path toPath:pathTo error:&error];
if (isMoveSuccess)
{
NSLog(@"移动成功");
}
else
{
NSLog(@"error %@",error);
}
*/
//3.删除
/*
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * path = @"/Users/aplle/Desktop/newmyfolder";
NSError * error;
BOOL isRemoveSuccess = [fileManager removeItemAtPath:path error:&error];
if (isRemoveSuccess)
{
NSLog(@"删除成功");
}
else
{
NSLog(@"erro %@",error);
}
*/
//4.拷贝文件
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * path = @"/Users/aplle/Desktop/myfolder";
NSString * pathTo = @"/Users/aplle/Desktop/newmyfolder";
NSError * error;
BOOL isCopySuccess = [fileManager copyItemAtPath:path toPath:pathTo error:&error];
if(isCopySuccess)
{
NSLog(@"拷贝成功");
}
else
{
NSLog(@"error %@",error);
}
}
return 0;
}