zoukankan      html  css  js  c++  java
  • Objective-C:Objective-C:文件中一些对目录进行操作的函数

    IO文件中,一些对目录进行操作的函数:获取、切分、组合

    一些对目录进行操作的函数:
    获取用户的姓名:(NSString*)NSUserName() ;    ———>NSString *Str = NSUserName()
    获取home目录路径:(NSString*)NSHomeDirectory()
    获取临时文件夹路径:(NSString*)NSTemporaryDirectory()
     
    一些对目录进行操作的方法:
    将路径切成部分:- (NSArray *)pathComponents  ———>NSArray *paths = [path pathComponents]
    将部分组合成路径:+ (NSString *)pathWithComponents:(NSArray *)components
    判断是不是绝对路径:- (BOOL)isAbsolutePath
    获取路径最后一部分:- (NSString *)lastPathComponent
    删除最后一部分:- (NSString *)stringByDeletingLastPathComponent
    获取扩展名:- (NSString *)pathExtension
    删除扩展名:- (NSString *)stringByDeletingPathExtension
    添加路径:- (NSString *)stringByAppendingPathComponent:(NSString *)str
    添加扩展名:- (NSString *)stringByAppendingPathExtension:(NSString *)str

    //1、获取home目录的路径

    1         NSString *homeDir = NSHomeDirectory();
    2         NSLog(@"home:%@",homeDir);
    2015-08-24 21:17:28.727 05-path[992:45425] home:/Users/mac

    //2、获取临时文件夹的路径

    1         NSString *tempDir = NSTemporaryDirectory();
    2         NSLog(@"home:%@",tempDir);
    2015-08-24 21:17:28.728 05-path[992:45425] home:/var/folders/dx/481d4y4j4430hfty5zr_1gfh0000gn/T/

     //3、将路径分成部分

    1         NSArray *paths = [tempDir pathComponents];
    2         NSLog(@"%@",paths);
    2015-08-24 21:17:28.728 05-path[992:45425] (
        "/",
        var,
        folders,
        dx,
        "481d4y4j4430hfty5zr_1gfh0000gn",
        T,
        "/"
    )

    //4、将部分再拼成路径

    1         NSString *path = [NSString pathWithComponents:paths];
    2         NSLog(@"%@",path);
    2015-08-24 21:17:28.729 05-path[992:45425] /var/folders/dx/481d4y4j4430hfty5zr_1gfh0000gn/T

    //5、在路径上添加文件

    1         NSString *fileNamePath = [path stringByAppendingPathComponent:@"1.txt"];
    2         NSLog(@"fileName:%@",fileNamePath);
    2015-08-24 21:17:28.729 05-path[992:45425] fileName:/var/folders/dx/481d4y4j4430hfty5zr_1gfh0000gn/T/1.txt

    //6、获取路径的最后一部分

    1         NSString *fileName = [fileNamePath lastPathComponent];
    2         NSLog(@"fileName:%@",fileName);
    2015-08-24 21:17:28.729 05-path[992:45425] fileName:1.txt

    //7、获取文件的扩展名

    1         NSString *extension = [fileNamePath pathExtension];
    2         NSLog(@"extension:%@",extension);
    2015-08-24 21:17:28.729 05-path[992:45425] extension:txt
    Program ended with exit code: 0
  • 相关阅读:
    获取数据——爬取某微博评论
    使用Microsoft Power BI进行基本的数据分析
    Hadoop分布式文件系统
    使用Visual Studio开发Python
    ML:吴恩达 机器学习 课程笔记(Week5~6)
    ML:吴恩达 机器学习 课程笔记(Week7~8)
    ML:吴恩达 机器学习 课程笔记(Week9~10)
    知乎用户报告
    ML:多变量代价函数和梯度下降(Linear Regression with Multiple Variables)
    ML:吴恩达 机器学习 课程笔记(Week1~2)
  • 原文地址:https://www.cnblogs.com/XYQ-208910/p/4755962.html
Copyright © 2011-2022 走看看