---
title: "Creating a directory in Documents in iOS"  
description: "Creating a directory in Documents in iOS"  
author: "Tarun Kumar"  
published: 2015-08-12  
updated: 2015-08-13  
canonical: https://www.mindstick.com/forum/33413/creating-a-directory-in-documents-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Creating a directory in Documents in iOS

I'm creating a folder in my [documents](https://www.mindstick.com/articles/156931/the-main-types-of-business-documents) [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp) and I want to do it without typing out /[Users](https://www.mindstick.com/news/2244/issue-preventing-users-from-accessing-facebook-s-social-networking-platforms-has-been-resolved)/([username](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username))/Documents/Foo/Bar

```
NSString *directoryPath = [NSString  stringWithFormat:@"%@/Documents/Foo/Bar", NSHomeDirectory()];     BOOL isDir;NSFileManager *fileManager= [NSFileManager defaultManager];if(![fileManager fileExistsAtPath:directoryPath isDirectory:&isDir])    if(![fileManager createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:NULL])        NSLog(@"Error: Create folder failed %@", directoryPath);
```

This doesn't work when I try using NSHomeDirectory() with it. But if I [typed](https://www.mindstick.com/interview/33645/what-is-the-difference-between-typed-and-untyped-dataset) out the [full](https://www.mindstick.com/articles/12893/experience-the-full-power-of-suitecrm) [path](https://www.mindstick.com/articles/44333/4-expert-tips-on-how-to-pick-the-right-career-path) /Users/(username)/Documents/Foo/Ba it works. How can it be done to not have to know the users folder?

EDIT: directoryPath becomes

```
/Users/(username)/Library/Developer/CoreSimulator/Devices/FAB78255-38D2-49BE-9683-7A0676EA2288/data/Containers/Data/Application/67B0AACE-572A-4808-9535-D221AEEB9EFA/Foo/Bar
```

I just want /Users/(username)

## Replies

### Reply by Anonymous User

This is an iOS app. The "Documents" folder of an iOS app's sandbox is not at all related to the user's "Documents" folder on their computer.

Since you appear to be running your iOS in the simulator, the path you are getting is more like what you should be seeing. You do not want a path in the user's home directory.

Keep in mind that you can't get access to the "Documents" folder of an iOS app using NSHomeDirectory(). That may have worked in older versions of iOS but it fails in iOS 8 and later. The proper code needs to be something like this:

```
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,                                NSUserDomainMask, YES);NSString *documentsFolder = paths[0];NSString *directoryPath = [documentsFolder stringByAppendingPathComponent:                                                @"Foo/Bar"];
```


---

Original Source: https://www.mindstick.com/forum/33413/creating-a-directory-in-documents-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
