How to get the url for a directory inside a document directory?

How can I get the URL for a specific directory inside the Document Directory.

like Document/Art/

My code

 - (NSURL *)localRoot { if (_localRoot != nil) { return _localRoot; } NSArray * paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]; _localRoot = [paths objectAtIndex:0]; return _localRoot; } 

This code is the URL for the Documents directory, but I need an Art path to the document directory.

+4
source share
4 answers
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *yourArtPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"]; 
+8
source

Use this

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@"/Art"]; 
+2
source

Application.StartupPath;

used to find your path in which your application starts, if that is what you mean.

0
source

Based on the answer above, this is a simple method that returns the path to a given directory:

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

You need to implement it in ClassName.m and call as:

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

All Articles