如何获取URL路径的文件目录的目录里面?(how to get URL Path for direc

2019-07-20 02:12发布

我怎样才能获得URL路径的文档目录内的特定目录。

Document/Art/

我的代码

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

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

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

上面的代码是URL路径Documents目录,但我需要Art的文件目录路径。

Answer 1:

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

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *yourArtPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"];


Answer 2:

用这个

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

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@"/Art"];


Answer 3:

Application.StartupPath;

是用来寻找你的路径在您的应用程序被启动,如果这是你的意思。



Answer 4:

基于上面的回答下面是一个简单的梅索德返回,路径定目录:

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

您需要实现它ClassName.m ,并呼吁为:

NSString *pathForDirectory = [ClassName pathFor:dirName]; //@"Art" in your case


文章来源: how to get URL Path for directory inside Document directory?