Sunday, 13 March 2011

Documents Directory File Path - iPhone, iPad, iOS Development

Getting the file path to the documents directory is very simple however the documentation in this area can be rather confusing.

Firstly you call the function NSSearchPathForDirectoriesInDomains(). This function returns an array however there will almost always only be one object within the array.

 NSArray * NSSearchPathForDirectoriesInDomains (  NSSearchPathDirectory directory,  NSSearchPathDomainMask domainMask,  BOOL expandTilde );

The reference for the method is shown above.
The Directory value must be one of the predefined search path directories of the operating system. The most commonly used directory and the one we'll use here is the documents directory which the value for is NSDocumentDirectory.  
Other values can be seen in the documentation here.
The domain mask value is most often NSUserDomainMask meaning the returned path is local to the user's home directory.  Other possible values are shown below.
 NSUserDomainMask - Local to the user's home directory.
 NSLocalDomainMask - local to the current machine.
 NSNetworkDomainMask - Publicly available location in the local area network.
 NSSystemDomainMask - /System (Usually unused private).
 NSAllDomainsMask - will return a path for each of the above domains.
The full example of how to obtain a string of the system file path to the user documents directory is shown below.
 -(NSString *)documentsDirectoryPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
return documentsDirectoryPath;


  1. Hello,
    The first thing you should do when looking to hire a freelance iPhone developer is to outline what type of development you need done for the iPhone.
    hire iphone Developer

  2. I posted a question on StackOverflow about NSSearchPathForDirectoriesInDomains - it's returning the wrong directory. Do you know why this would be happening?

  3. I have read this post. collection of post is a nice one ..that am doing website designing company chennai india and website development company chennai india. That I will inform about your post to my friends and all the best for your future posts..

  4. Now day's demand of iPhone application is increasing very fast. This is the appropriate blog for any iPhone developer who wants to outsource their iPhone application development.

  5. Thanks For Sharing This Post

    For More Information You Can Visit This Website iPhone Application Development Solutions

  6. Nice Post ..!! I really i like the way of your writing this post. You have shared a very interesting and informative post about Mobile platform .. keep Updating..!!
    Android Application Development

  7. If you are searching for cost effective as well as solid Mobile Application Development Services and Web Development in India provider then without thinking much you can choose to hire the services offered by Acetech. We are one of the leading companies offering affordable, timely and quality mobile apps services.

  8. Today all users crazy about new iphone apps and iPhone become more necessary for people even businesspersons. If you want to development customs, iphone application development then must hire a well-reputed development company.

  9. Great article ...Thanks for your great information, the contents are quiet interesting. I will be waiting for your next post.
    iphone app development usa

  10. I am glad after reading your technical blog... Your blog is excellent & you are helping others by posting these type of articles publicly... Appreciated
    biggest iphone apps development company

  11. Thanks for giving knowledge Excellent overview :)
    android developer USA

  12. Thanks so much for such a useful collection. And i must tell you guys , it is worth visiting our page for more relevant information and iphone apps development works and services..