---
title: "How to use coverted nsstring into FSCreateDirectoryUnicode?"  
description: "How to use coverted nsstring into FSCreateDirectoryUnicode?"  
author: "Royce Roy"  
published: 2016-01-11  
updated: 2016-01-13  
canonical: https://www.mindstick.com/forum/33849/how-to-use-coverted-nsstring-into-fscreatedirectoryunicode  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to use coverted nsstring into FSCreateDirectoryUnicode?

I'm a [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in Objective-C, I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) in our app but its not working correctly. I think on calling **FSCreateDirectoryUnicode**- I don not get the correct [length](https://www.mindstick.com/interview/1915/what-is-the-difference-between-char_length-and-length).\
Can you tell me how can I get the correct length or what will be the simplest way to do it?\
this is my code:\

```
NSString *strObj = @"DirectoryName";NSData *dataObj = [strObj dataUsingEncoding:NSUnicodeStringEncoding                          allowLossyConversion:NO];FSCreateDirectoryUnicode(&aFolderFSRef, [strObj length], [dataObj bytes],                          kFSCatInfoNone, NULL, &newFolderFSRef, NULL, NULL);
```

## Replies

### Reply by Tarun Kumar

I found many issues with your source string data. In Cocoa the easiest way to do that is:

```
NSString *strObj = @"DirectoryName";NSString *strPath = [NSHomeDirectory() stringByAppendingPathComponent:strObj];[[NSFileManager defaultManager] createDirectoryAtPath:strPath attributes:nil];
```

We can use FSRef for specifying the created directory path. In our example we use home directory instead. If we really use the directory in the FSRef & don't know the path, it will be easier to use the FSCreateDirectoryUnicode function:Here is the correct encoding of the above code:

```
NSString *strObj = @"DirectoryName";const UniChar *name = (const UniChar*)[strObj cStringUsingEncoding:NSUnicodeStringEncoding];FSCreateDirectoryUnicode(&aFolderFSRef, [strObj length], name, kFSCatInfoNone, NULL, &newFolderFSRef, NULL, NULL);
```


---

Original Source: https://www.mindstick.com/forum/33849/how-to-use-coverted-nsstring-into-fscreatedirectoryunicode

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
