Thursday, November 02, 2006

MakeSureDirectoryPathExists

The powerfully WinApi-Function 'MakeSureDirectoryPathExists' implementet in X++!

The MakeSureDirectoryPathExists function creates all the directories in the specified _filePath, beginning with the root.

This function resides in imagehlp.dll, but also in
dbghelp.dll.
Take a look to http://msdn2.microsoft.com/en-us/library/ms680352.aspx

static int MakeSureDirectoryPathExits(FilePath _filePath)
{
/*
fa 20061102
Returnvalue:
0... OK
>0.. Error
*/

#define.imagehlp('imagehlp.dll')
DLL winApiDLL = new DLL(#imagehlp);
DLLFunction pathExits = new DLLFunction(winApiDLL, 'MakeSureDirectoryPathExists');
int retVal = 0;
;
if(substr(_filePath, strlen(_filePath), 2) != "\\")
_filePath += "\\";


pathExits.returns(ExtTypes::DWord);
pathExits.arg(ExtTypes::String);

if (pathExits.call(_filePath) == 0)
{
retVal = WinAPI::getLastError();
retVal = retVal == 0 ? 1 : retVal;
}

return retVal;

}

No comments: