iOS檔案路徑相關的方法

來源:互聯網
上載者:User

標籤:檔案的   ast   content   刪除   extension   with   white   documents   last   

檔案路徑相關的方法在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

iOS檔案路徑相關的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.