首页 > 其他 > 详细

NSPathUtilities,关于文件路径的几个常用操作

时间:2015-05-06 19:45:35      阅读:221      评论:0      收藏:0      [点我收藏+]

NSPathUtilities,关于文件路径的几个常用操作,熟悉一下,拼接路径什么的,感觉还是挺好使的。

//原路径。随便在项目中添加了张图片,用于测试
NSString *strPath =[[NSBundle mainBundle] pathForResource:@"002" ofType:@"png"];
NSLog(@"path======%@", strPath);

//获取路径的最后一层
NSString *strAllName = [strPath lastPathComponent];
NSLog(@"allName===%@",strAllName);

//去掉路径的最后一层
NSString *strFilePath = [strPath stringByDeletingLastPathComponent];
NSLog(@"filePath==%@",strFilePath);

//去掉扩展名
NSString *strName = [strAllName stringByDeletingPathExtension];
NSLog(@"strName===%@",strName);

//获取扩展名
NSString *strExtension = [strPath pathExtension];
NSLog(@"extension=%@",strExtension);

运行结果
 
2015-05-06 18:20:48.638 test03[3470:1708111] path======/private/var/mobile/Containers/Bundle/Application/9A142EC0-A29F-42DF-AFF6-C36E448271AE/test03.app/002.png
2015-05-06 18:20:48.639 test03[3470:1708111] allName===002.png
2015-05-06 18:20:48.640 test03[3470:1708111] filePath==/private/var/mobile/Containers/Bundle/Application/9A142EC0-A29F-42DF-AFF6-C36E448271AE/test03.app
2015-05-06 18:20:48.640 test03[3470:1708111] strName===002
2015-05-06 18:20:48.641 test03[3470:1708111] extension=png


NSPathUtilities,关于文件路径的几个常用操作

原文:http://blog.csdn.net/u011439689/article/details/45539027

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!