how to get URL Path for directory inside Document directory?
13,923
Solution 1
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *yourArtPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
Solution 2
Use this
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
Related videos on Youtube
Comments
-
Vijay almost 2 years
How can I get url path for a particular directory inside 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; }
The above code is url path for
Documents
directory but I needArt
document directory path. -
Vijay about 11 yearsits NSString i need NSURL so which method i will use insed of stringByAppendingPathComponent:
-
Sumit Mundra about 11 yearsadd this line also NSURL *url = [NSURL URLWithString:appFile_a];
-
Vijay about 11 years- (NSURL *)localRoot { if (_localRoot != nil) { return _localRoot; } NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *artdirectoryPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"]; _localRoot=[NSURL URLWithString:artdirectoryPath]; return _localRoot; } this my updated Code but still i got error..
-
Vijay about 11 yearswhile go to path -[NSFileManager contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:]: URL is nil'
-
rptwsthi about 11 yearsNSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@\"Art\"]; have bug at `@"\Art"`
-
Robin Garg almost 7 yearsWhen we use path component then there is no need to add "/" with component