[ColdBox 3.8.5] Help! The specified directory could not be created

I have lots of documents being created, and each document gets assigned a UUID. The way the file system is structured, is the it takes every 2 characters the first 8 UUID and create a directory tree to store the file:

i.e. 8F2BC545-19B9-0929-6EA87983A0CB53F6.pdf will be stored in: C:<storageRoot>\8F\2B\C5\45\8F2BC545-19B9-0929-6EA87983A0CB53F6.pdf

I’m using the below function to create the directories, but still get the following error (though not every time):
The specified directory C:\IMTMRO\MROEntities\1\Documents\8F\2B could not be created.
The most likely cause of this error is that C:\IMTMRO\MROEntities\1\Documents\8F\2B already exists on your file system.

What gives? Doesn’t the if statement with DIRECTORYEXISTS supposed to keep this from happening?

`

`

Any help is appreciated.
-Chris

Does it exist? The error simply says that’s the most likely cause. it could also be some sort of permission issue. Inspect the FULL stack trace for more info.

Also, isn’t the value of “to” sort of redundant since you’re creating a string of exactly 8 characters and then checking its length? Save yourself some code and just do this:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com