NSFileManager(文件管理)

NSFileManager 文件管理的类继承于NSObject。连接苹果官方文档:

https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/


//创建对象

   NSFileManager    *fileManager = [NSFileManager defaultManager];
//     判断在某个路径下的文件是否存在 
    if (![fileManager fileExistsAtPath:[self getPath]]) {
//       如果这个目录不存在就createDirectoryAtPath

        [ fileManager createDirectoryAtPath:[self getPath] withIntermediateDirectories:YES attributes:nil error:nil];


    }

//获取源文件路径,假设源文件是001.rdfd
   NSString  *path1 =  [[NSBundle mainBundle]pathForResource:@"001" ofType:@"rtfd"];
   //copy
   [fileManager copyItemAtPath:path1 toPath:[self getPath2] error:nil];

   //move 
   [fileManager moveItemAtPath:[self getPath2] toPath:[self getPath3] error:nil];
    NSLog(@"%@",[self getPath]);

//    remove 
    [fileManager removeItemAtPath:[self getPath3] error:nil];

}
- (NSString *)getPath{
    NSString   *str = [NSString stringWithFormat:@"%@/Documents/123",NSHomeDirectory()];
    return str;
}

- (NSString *)getPath2{

    NSString *str = [NSString stringWithFormat:@"%@/Documents/test.rtf",NSHomeDirectory()];

    return str;
}

- (NSString *)getPath3{
       return  [NSString stringWithFormat:@"%@/Documents/123/test.rtf",NSHomeDirectory()];

}





@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值