自己写的,自认为还可以看,发出来全当备份。
PS:渣浪博客没办法插入代码么?
BOOL IsPathExistA(
LPCSTR lpPathName
)
{
if(GetFileAttributesA(lpPathName) != 0xFFFFFFFF)
{
return TRUE;
}
return FALSE;
}
BOOL IsPathExistW(
LPCWSTR lpPathName
)
{
if(GetFileAttributesW(lpPathName) != 0xFFFFFFFF)
{
return TRUE;
}
return FALSE;
}
#ifdef UNICODE
#define IsPathExist IsPathExistW
#else
#define IsPathExist IsPathExistA
#endif // !UNICODE
BOOL CreateDirectoryReA(
LPCSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
{
CHAR Path[MAX_PATH];
LPCSTR Token = lpPathName;
LONG Size;
BOOL Ret;
if(IsPathExistA(lpPathName))
{
return FALSE;
}
while((Token = strchr(Token, '\\')))
{
Size = Token - lpPathName;
strncpy(Path, lpPathName, Size);
Path[Size] = '\0';
Token++;
if(IsPathExistA(Path) == FALSE)
{
Ret = CreateDirectoryA(Path, lpSecurityAttributes);
if(Ret == FALSE)
{
return Ret;
}
}
}
return CreateDirectoryA(lpPathName, lpSecurityAttributes);
}
BOOL CreateDirectoryReW(
LPCWSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
{
WCHAR Path[MAX_PATH];
LPCWSTR Token = lpPathName;
LONG Size;
BOOL Ret;
if(IsPathExistW(lpPathName))
{
return FALSE;
}
while((Token = wcschr(Token, '\\')))
{
Size = Token - lpPathName;
wcsncpy(Path, lpPathName, Size);
Path[Size] = '\0';
Token++;
if(!IsPathExistW(Path))
{
Ret = CreateDirectoryW(Path, lpSecurityAttributes);
if(Ret == FALSE)
{
return Ret;
}
}
}
return CreateDirectoryW(lpPathName, lpSecurityAttributes);
}
#ifdef UNICODE
#define CreateDirectoryRe CreateDirectoryReW
#else
#define CreateDirectoryRe CreateDirectoryReA
#endif // !UNICODE