# Create() and createDirectory() is not working properly

**URL:** <https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661>\
**Category:** General JUCE discussion\
**Created:** [September 14, 2010, 6:21am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661 "2010-09-14T06:21:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![godwincharan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/godwincharan/32/213_2.png) [@godwincharan](https://forum.juce.com/u/godwincharan)\
**Post date:** [September 14, 2010, 6:21am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/1 "2010-09-14T06:21:09Z")

</div>

Hi Jules,  
The create and createDirectory is not working fine with latest juce GIT code. In Mac create Directory is not creating the directory instead its creating one file of the same name. And in PC the create is not creating the file in the proper destination (even if the destination directory exist ).

Thanks  
CGD

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 14, 2010, 8:29am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/2 "2010-09-14T08:29:53Z")

</div>

Well, this week I added a set of unit tests for the File class, and the tests definitely include createDirectory() - so I’m pretty confident that it does work correctly! Can you give me some test code that would reproduce the problem?

---

<div class="post-metadata">

**Author:** ![godwincharan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/godwincharan/32/213_2.png) [@godwincharan](https://forum.juce.com/u/godwincharan)\
**Post date:** [September 14, 2010, 9:38am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/3 "2010-09-14T09:38:47Z")

</div>

I m using JUCE 1.52.49, ( afraid to take latest version ) and I m working in windows XP.

```auto
juce::String sMyFolderPath( T("C:\Program Files\Common Files\MyFolder\"));
juce::File myFolder( sMyFolderPath );
			
if ( myFolder.isDirectory() == false )
{
	bool b = myFolder.createDirectory();
}
```

---

<div class="post-metadata">

**Author:** ![godwincharan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/godwincharan/32/213_2.png) [@godwincharan](https://forum.juce.com/u/godwincharan)\
**Post date:** [September 14, 2010, 10:11am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/4 "2010-09-14T10:11:55Z")

</div>

sorry little confusion…That was for mac code.

It was not able to create directory in mac. and file in PC

I found out the possible reason in the PC side.

the

```auto
void* juce_fileOpen (const File& file, bool forWriting)
```

has the line

```auto
if (forWriting)
    {
        h = CreateFile (file.getFullPathName(), GENERIC_WRITE, [color=#FF0000]FILE_SHARE_READ[/color], 0,
                        OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
```

the third argument should be also FILE\_SHARE\_WRITE as the document says

> [@](#):
>
> If this flag is not specified, but the file or device has been opened for write access or has a file mapping with write access, the function fails.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 14, 2010, 11:20am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/5 "2010-09-14T11:20:25Z")

</div>

```auto
juce::String sMyFolderPath( T("C:\Program Files\Common Files\MyFolder\"));
```

…ahem… you might want to have a careful look at those backslash escape sequences. Maybe DBG the filename that you’re trying to create before assuming that something else is failing!

---

<div class="post-metadata">

**Author:** ![godwincharan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/godwincharan/32/213_2.png) [@godwincharan](https://forum.juce.com/u/godwincharan)\
**Post date:** [September 14, 2010, 11:51am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/6 "2010-09-14T11:51:20Z")

</div>

that was for example… thats not the actual file name  
I was using the windows call to get the file location ::SHGetSpecialFolderPath(NULL,str,CSIDL\_COMMON\_APPDATA,NULL);

think that it gives the path as “C:\Program Files\Common Files” i myself append the file name at the end. and i create the file name based on the time.

```auto
juce::String filePath = CommonDataPath + juce::Time::getCurrentTime().toString( true , true , true , true ) + juce::String(".xml");
```

and i use this path to create file using

```auto
juce::File file( filePath );
file.create()
```

so there is no issue in the file name…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 14, 2010, 11:55am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/7 "2010-09-14T11:55:09Z")

</div>

If createDirectory failed, then pretty much no applications would work. So it’s going to take quite a lot to convince me that this isn’t just you doing something silly.

Did you actually DBG the filename you’re trying to create? If so, what is it?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 14, 2010, 11:56am UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/8 "2010-09-14T11:56:51Z")

</div>

…and why are you using strings, anyway? Never, never concatenate filenames using strings - always use the File class to do it safely. And why not just use File::getSpecialLocation to get the apps folder??

---

<div class="post-metadata">

**Author:** ![godwincharan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/godwincharan/32/213_2.png) [@godwincharan](https://forum.juce.com/u/godwincharan)\
**Post date:** [September 14, 2010, 12:13pm UTC](https://forum.juce.com/t/create-and-createdirectory-is-not-working-properly/5661/9 "2010-09-14T12:13:06Z")

</div>

i got it clear…

the problem was in “:” from juce::Time::getCurrentTime().toString( true , true , true , true )…  
I developed the code in mac and then tried building in PC. the Mac system accepted “:” in the file name…

i guessed u r creating valid file name for the files and throwing assertion if the filename is contains invalid characters…  
I m running in debug mode still it dint throw any assertion.
