复制和移动文件



#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool
    {
        //from路径
        NSString *frompath = [NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES) lastObject];
        //to路径
        NSString *topath = [frompath stringByAppendingPathComponent:@"innerMoreHappy/2/3/4/22.png"];
        frompath = [frompath stringByAppendingPathComponent:@"w.png"];
        // FileManager 单例
        NSFileManager *filemanager = [NSFileManager defaultManager];
        // 如果没有上层目录则创建 参数二:可多层创建
        [filemanager createDirectoryAtPath:[topath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
        //移动文件从from to to
        [filemanager moveItemAtPath:frompath toPath:topath error:nil];
        //修改from目录
        frompath = [[frompath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"3.png"];
        //拷贝文件从to to from
        [filemanager copyItemAtPath:topath toPath:frompath error:nil];
        //读取属性
        NSDictionary * nsdic = [filemanager attributesOfItemAtPath:frompath error:nil];
        NSLog(@"nsdic:%@", nsdic);
        //读取FileSize属性
        NSNumber * size = [nsdic objectForKey:NSFileSize];
        int sizea = [size intValue];
        NSLog(@"size:%d",sizea);
        
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值