#include <string.h>

#include "Desk.Filing.h"
#include "Desk.File.h"
#include "DeskLib:Error2.h"
#include "Desk.Debug.h"
#include "Desk.Str.h"



void	Desk_File_EnsureDirectory( const char* path)
{
char	path2[ 256];
char*	c;

strcpy( path2, path);

if ( Desk_File_IsDirectory( path))	return;

c = Desk_Filing_FindLeafname( path2);
if ( c>path2)	{
	c[-1] = 0;
	Desk_File_EnsureDirectory( path2);
	c[-1] = '.';
	Desk_Error2_CheckOS( Desk_File_CreateDirectory( path2));
	Desk_Debug_Printf( "Created directory '%s'\n", path2);
	}
}



void	Desk_File_EnsureParentDirectory( const char* filename)
{
char	dir[ 256];
char*	leaf = Desk_Filing_FindLeafname( filename);

if (leaf==filename)	Desk_Error2_HandleTextf( "Desk_File_EnsureParentDirectory:'%s' has no parent", filename);
Desk_Debug_Printf( "EnsureParentDir '%s'\n", filename);
strncpy0( dir, filename, (leaf-filename) - 1);
Desk_File_EnsureDirectory( dir);
}
