oOOMIAO
oOOMIAO
采纳率66%
2013-02-19 02:14

如何获取文件目录内部的目录URL路径

如何获取特定的目录URL路径?

比如Document/Art/

代码:

- (NSURL *)localRoot {
if (_localRoot != nil) {
    return _localRoot;
}

NSArray * paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];

_localRoot = [paths objectAtIndex:0];
return _localRoot;
}

上面的代码可以获取Documents目录的路径,但是怎么获取ART的路径?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • love_loveec love_loveec 8年前

    根据上面的回答
    有一种简单的返回目录方法:

    + (NSString *) pathFor : (NSString *) directoryName{
        return [[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:directoryName];
    }
    

    需要在ClassName.m中实现并且调用:

    NSString *pathForDirectory = [ClassName pathFor:dirName]; //@"Art" in your case
    
    点赞 评论 复制链接分享
  • Chengzi_963 Chengzi_963 8年前
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSString *yourArtPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
    
    点赞 评论 复制链接分享
  • redCoral_ redCoral_ 8年前

    试试这个:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
    
    点赞 评论 复制链接分享