复制和移动文件

来源:互联网 发布:shell执行sql脚本 编辑:程序博客网 时间:2024/05/16 18:31


#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;}


0 0
原创粉丝点击