CE上可以递归创建目录的CreateDire…

自己写的,自认为还可以看,发出来全当备份。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值