【问题标题】:How to get a filepath from a directory without file name in iOS Objective c如何在iOS Objective c中从没有文件名的目录中获取文件路径
【发布时间】:2016-02-25 09:26:11
【问题描述】:

美好的一天

如何从完整路径中获取没有文件名的文件路径。 假设我有一条路径:

NSString *myPath = @"/Users/myName/Library/Developer/CoreSimulator/Devices/.../Library/Caches/Getting Started.pdf";

我只想拥有

NSString *newPath = @"/Users/myName/Library/Developer/CoreSimulator/Devices/.../Library/Caches";

我不想子串它,希望有更好的解决方案。

提前谢谢你。

【问题讨论】:

    标签: objective-c


    【解决方案1】:

    检查NSString的类引用。

    newPath = [path stringByDeletingLastPathComponent];
    

    【讨论】:

    • 这正是我一直在寻找的。你是个天才 。非常感谢@Avi
    【解决方案2】:

    试试这个代码

      NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
        NSLog(@" DocumentPath %@",documentPath);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-09
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多