NSPathUtilities.h

    //通过数组创建路径
    NSArray *arr = @[@"aaa", @"bbb", @" ", @"ccc"];
    NSString *path = [NSString pathWithComponents:arr];
    
    //将路径分解成数组
    path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"plist"];
    NSArray *array = path.pathComponents;
    
    //判断是否是绝对路径
    BOOL flag = path.isAbsolutePath;
    
    //获取路径的最后一个组成部分
    NSLog(@"%@", path.lastPathComponent);
    
    //去除路径的最后一个组成部分
    NSLog(@"%@", path.stringByDeletingLastPathComponent);
    
    //拼接路径
    NSLog(@"%@", [path stringByAppendingPathComponent:@"ffff.xxx"]);
    
    //获取路径扩展名
    NSLog(@"%@", path.pathExtension);
    
    //去除路径的扩展名
    NSLog(@"%@", path.stringByDeletingPathExtension);
    
    //添加扩展名
    NSLog(@"%@", [path stringByAppendingPathExtension:@".vvvv"]);
    
    //将主路径替换成~
    NSString *document = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    NSString *tildePath = [document stringByAbbreviatingWithTildeInPath];
    NSLog(@"%@", tildePath);
    
    //将~替换成主路径
    NSLog(@"%@", tildePath.stringByExpandingTildeInPath);

NSLog(@"%@", path.stringByStandardizingPath);
    
    //还原路径中的符号链接,例如"~"、".."符号等
    NSLog(@"%@", path.stringByResolvingSymlinksInPath);
   
    //对路径字符串分别添加字典中的每个路径,形成数组
    NSArray *array = [path stringsByAppendingPaths:@[@"xiaobai", @"xiaohei"]];
    NSLog(@"%@", array);

    //将字符串转成文件系统路径,以utf-8格式编码
    path.fileSystemRepresentation;
    
    //筛选数组中指定扩展名的路径
    NSArray *arr = @[@"/var/mobile/Containers/Data/Application/583B3A9B-FD29-4517-9EF8-31A40E47D6FC/Documents/1.txt", @"/var/mobile/Containers/Data/Application/583B3A9B-FD29-4517-9EF8-31A40E47D6FC/Documents/2.doc",@"/var/mobile/Containers/Data/Application/583B3A9B-FD29-4517-9EF8-31A40E47D6FC/Documents/3.txt"];
    NSArray *temp = [arr pathsMatchingExtensions:@[@"txt", @"plist"]];

    //completePathIntoString,不清楚是干嘛的
    NSString *path = @"/var/mobile/Containers/Data/Application/583B3A9B-FD29-4517-9EF8-31A40E47D6FC/Documents/1.txt";
    NSString *str = @"";
    NSArray *arrtemp = [NSArray array];
    [path completePathIntoString:&str caseSensitive:NO matchesIntoArray:&arrtemp filterTypes:@[@"txt"]];
    
    NSLog(@"%@", [NSString stringWithUTF8String:path.fileSystemRepresentation]);

 

 

转载于:https://my.oschina.net/mexiaobai1315/blog/1806995

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值