zoukankan      html  css  js  c++  java
  • OC7_目录操作

    //
    //  main.m
    //  OC7_目录操作
    //
    //  Created by zhangxueming on 15/6/19.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            NSFileManager *fm = [NSFileManager defaultManager];
            
            //- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error
            //获取文件或者目录的属性信息
            NSDictionary *attribute = [fm attributesOfItemAtPath:@"/Users/zhangxueming/Desktop/city.plist" error:nil];
            NSLog(@"attribute = %@", attribute);
            NSLog(@"size = %@", [attribute objectForKey:@"NSFileSize"]);
            //- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error
            
            NSDictionary *attri = [fm attributesOfFileSystemForPath:@"/Users/zhangxueming/Desktop/city.plist" error:nil];
            NSLog(@"attri = %@", attri);
            
            NSLog(@"size  = %lli", [attri fileSize]);
            
            //文件及目录拷贝
    //        - (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error
            //dstPath:必须包含目的文件名或者目录名
            BOOL ret = [fm copyItemAtPath:@"/Users/zhangxueming/Desktop/city.plist" toPath:@"/Users/zhangxueming/Desktop/Test/city.plist" error:nil];
            if (ret) {
                NSLog(@"拷贝成功");
            }
            else{
                NSLog(@"拷贝失败");
            }
            //文件及目录移动(重命名)
    //        - (BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error
            //srcPath与dstPath路径相同是重命名的功能, 否则是移动功能
            ret = [fm moveItemAtPath:@"/Users/zhangxueming/Desktop/Test/中国象棋" toPath:@"/Users/zhangxueming/Desktop/Test/chess" error:nil];
            if (ret) {
                NSLog(@"移动成功");
            }
            else
            {
                NSLog(@"移动失败");
            }
            
            //删除文件或者目录
    //        - (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error
            ret = [fm removeItemAtPath:@"/Users/zhangxueming/Desktop/Test/chess" error:nil];
            if (ret) {
                NSLog(@"删除成功");
            }
            else{
                NSLog(@"删除失败");
            }
            
            //- (BOOL)fileExistsAtPath:(NSString *)path;
            //判断文件是否存在
            ret = [fm fileExistsAtPath:@"/Users/zhangxueming/Desktop/Test/file1"];
            NSLog(@"ret = %i", ret);
        }
        return 0;
    }
  • 相关阅读:
    [转载]SQL Server行列转换实现
    [转载]依赖注入那些事
    [转载]MVC、MVP以及Model2(下)
    [转载]MVC、MVP以及Model2(上)
    SQL Server中CROSS APPLY和OUTER APPLY应用
    Open XML操作Excel导入数据
    centos7 firewall-cmd 理解多区域配置中的 firewalld 防火墙
    centos7 firewall-cmd 用活firewalld防火墙中的zone
    个税起征点上调,你每月能省多少?最后还有点凉水
    2018年中国500强排行榜
  • 原文地址:https://www.cnblogs.com/0515offer/p/4589586.html
Copyright © 2011-2022 走看看