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"];
Share:
13,923

Related videos on Youtube

Vijay
Author by

Vijay

iOS Developer

Updated on July 11, 2022

Comments

  • Vijay
    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 need Art document directory path.

  • Vijay
    Vijay about 11 years
    its NSString i need NSURL so which method i will use insed of stringByAppendingPathComponent:
  • Sumit Mundra
    Sumit Mundra about 11 years
    add this line also NSURL *url = [NSURL URLWithString:appFile_a];
  • Vijay
    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
    Vijay about 11 years
    while go to path -[NSFileManager contentsOfDirectoryAtURL:includingPropertiesForKeys:options:‌​error:]: URL is nil'
  • rptwsthi
    rptwsthi about 11 years
    NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@\"Art\"]; have bug at `@"\Art"`
  • Robin Garg
    Robin Garg almost 7 years
    When we use path component then there is no need to add "/" with component