tags:

views:

42

answers:

1

How to get the location of the file in mac os using objective c?

/Users/objc/Downloads/x.pdf

Any foundation classes for this?

please give me some sample code.

+1  A: 

Not sure whether I understand what you want, but you get the user's home directory with:

NSArray *docDirs = NSSearchPathForDirectoriesInDomains(
                    NSDownloadsDirectory,
                    NSUserDomainMask, YES);
NSString *doc = [docDirs objectAtIndex:0];

And then you can construct the path:

NSString *path = [NSString stringWithFormat:@"%@/x.pdf", doc];
DarkDust
The cleaner way is to use stringByAppendingPathComponent:. NSString *path = [doc stringByAppendingPathComponent:@"x.pdf"];, which will automatically insert the directory separation character.
muffix
@Björn: Oh, didn't know that one. Thanks !
DarkDust
Also, you want `NSDownloadsDirectory`, not `NSDocumentationDirectory`. (Note that `NSDocumentationDirectory` is usually `~/Library/Documentation`, which is different from `NSDocumentDirectory`, which is `~/Documents`.)
mipadi
DarkDust