zoukankan      html  css  js  c++  java
  • iOS文件路径相关的方法

    文件路径相关的方法在NSPathUtilities中,主要是操作路径

    得一个路径

     NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; //获得Document的路径<pre name="code" class="objc">//---~~~/Application/43A22272-F08C-4078-93A9-CAF451BF9814/Documents  //~~~是省略写法
    
    

    
    
    NSArray *components = [documents pathComponents]; //路径的每一个节点的元素<pre name="code" class="objc">     
         "/",
         Users,
         admin,
         Library,
         Developer,
         CoreSimulator,
         Devices,
         "87AB942E-1A11-479C-8010-1F5C36646658",
         data,
         Containers,
         Data,
         Application,
         "43A22272-F08C-4078-93A9-CAF451BF9814",
         Documents
    
    
    
    NSString *lastPathComponent = [documents lastPathComponent]; //最后的一个路径节点元素
        //---Documents
    
    
    NSString *stringByDeletingLastPathComponent = [documents stringByDeletingLastPathComponent];//删除最后一个路径节点元素
        //---~~~/Application/3B14DAE5-8890-42E1-8DC1-664BB35B6333
    NSString *stringByAppendingPathComponent = [documents stringByAppendingPathComponent:@"new.txt"]; //加入一个路径元素
        //---~~~/Application/20FED3FC-859A-4C56-945A-FFEEB17A93A2/Documents/new.txt
    NSString *pathExtension = [stringByAppendingPathComponent pathExtension];  //文件的后缀名
        //---txt
    NSString *stringByDeletingPathExtension = [stringByAppendingPathComponent stringByDeletingPathExtension]; //去掉后缀名
        //---~~~/Application/20FED3FC-859A-4C56-945A-FFEEB17A93A2/Documents/new
    NSString *stringByAppendingPathExtension = [stringByDeletingPathExtension stringByAppendingPathExtension:@"txt"]; //加入后缀名
        //---~~~/Application/20FED3FC-859A-4C56-945A-FFEEB17A93A2/Documents/new.txt
    NSString *stringByAbbreviatingWithTildeInPath = [documents stringByAbbreviatingWithTildeInPath];  //变成相对路径,前面的都用波浪号省略
        //--- ~/Documents
    NSString *stringByExpandingTildeInPath = [stringByAbbreviatingWithTildeInPath stringByExpandingTildeInPath]; //把相对路径变成绝对路径
    NSArray *stringsByAppendingPaths = [documents stringsByAppendingPaths:@[@"a",@"b",@"c.txt"]];  //批量加入多个路径,得到一个路径数组
        //---~~~/Application/16474B22-B287-4F7C-9931-E7454B83822E/Documents/a
        //---~~~/Application/16474B22-B287-4F7C-9931-E7454B83822E/Documents/b
        //---~~~/Application/16474B22-B287-4F7C-9931-E7454B83822E/Documents/c.txt

  • 相关阅读:
    软件命名规则
    从命令行git转到Tortoise
    如何让浏览器不解析html?
    说几点我觉得谷歌浏览器不好的地方
    移动端开发:使用jQuery Mobile还是Zepto
    开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
    给大家讲个故事,感受一下什么叫CF。不知道的请认真听。
    cmd中utf-8编码的问题
    web前端关于html转义符的常用js函数
    js实例分析JavaScript中的事件委托和事件绑定
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/6771219.html
Copyright © 2011-2022 走看看