|
// This code is from an article by Arlen Albert at:
// http://www.codeguru.com/Cpp/W-P/files/folderdirectorymaintenance/article.php/c4469/
#include "stdafx.h"
#include <io.h>
BOOL MakeSurePathExists(CString &Path, BOOL FilenameIncluded=TRUE)
{
int Pos=0;
while((Pos=Path.Find('\\',Pos+1))!=-1)
CreateDirectory(Path.Left(Pos),NULL);
if(!FilenameIncluded)
CreateDirectory(Path,NULL);
return ((!FilenameIncluded)?!_access(Path,0):
!_access(Path.Left(Path.ReverseFind('\\')),0));
}
int make_sure_path_exists(const char *iPath, BOOL FilenameIncluded=TRUE)
{
char *Path=(char*)iPath,
*TmpPath=Path,
TmpSmb=0,
*LastDPtr=NULL;
while((TmpPath=strpbrk(TmpPath+1,"\\/")))
{
TmpSmb=Path[TmpPath-Path];
Path[TmpPath-Path]=0;
CreateDirectory(Path,NULL);
Path[TmpPath-Path]=TmpSmb;
LastDPtr=TmpPath;
}
int Res=1;
if(!FilenameIncluded)
{
CreateDirectory(iPath,NULL);
Res=!_access(iPath,0);
}
else
{
if(LastDPtr)
{
Path=(char*)iPath;
TmpSmb=Path[LastDPtr-Path];
Path[LastDPtr-Path]=0;
Res=!_access(Path,0);
Path[LastDPtr-Path]=TmpSmb;
}
}
return Res;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.