Vijay
Vijay

Reputation: 579

how to get URL Path for directory inside Document directory?

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.

Upvotes: 5

Views: 14001

Answers (4)

rptwsthi
rptwsthi

Reputation: 10172

Based on above answer here is an simple methode that returns, path for 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

Upvotes: 0

Sumit Mundra
Sumit Mundra

Reputation: 3901

Use this

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

NSString *documentsDirectory = [paths objectAtIndex:0];

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

Upvotes: 1

Rajneesh071
Rajneesh071

Reputation: 31073

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

NSString *documentsDirectory = [paths objectAtIndex:0];

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

Upvotes: 12

user1547355
user1547355

Reputation:

Application.StartupPath;

is used to find your path where your application is being started, if that is what you mean.

Upvotes: 0

Related Questions