I had some code, there, hold on where is it...
// make output directory
length = strlen (output_file);
for (index = 0; index < length; index++)
if ((output_file[index] == '/') || (output_file[index] == '\\'))
strncpy (dirname, output_file, index);
dirname[index] = 0;
POSIX_mkdir (dirname, 666); // build each subdirectory recursively if needed
output_file is a full pathname
dirname must be a writable string
POSIX_mkdir is #defined like this:
#define POSIX_mkdir(a,b) _mkdir(a)
#define POSIX_mkdir(a,b) mkdir(a,b)
That code will parse the path and call mkdir on each subdirectory recursively. If the directory already exists, it will leave it as is and mkdir will return ; if it doesn't exist, it will be created. This ensures you always have a correct path.