我怎样才能获得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
的文件目录路径。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *yourArtPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
用这个
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
Application.StartupPath;
是用来寻找你的路径在您的应用程序被启动,如果这是你的意思。
基于上面的回答下面是一个简单的梅索德返回,路径定目录:
+ (NSString *) pathFor : (NSString *) directoryName{
return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:directoryName];
}
您需要实现它ClassName.m
,并呼吁为:
NSString *pathForDirectory = [ClassName pathFor:dirName]; //@"Art" in your case