2 ooomiao oOOMIAO 于 2013.02.19 10: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个回答

redCoral_
redCoral_   2013.02.19 13:40

试试这个:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
Chengzi_963
Chengzi_963   2013.02.19 15:05
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *yourArtPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
love_loveec
love_loveec   2013.02.19 15:44

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

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

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

NSString *pathForDirectory = [ClassName pathFor:dirName]; //@"Art" in your case
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!