Chinaunix首页 | 论坛 | 博客
  • 博客访问: 578665
  • 博文数量: 752
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:47
文章分类

全部博文(752)

文章存档

2011年(1)

2008年(751)

我的朋友

分类:

2008-10-13 16:49:08

kenping:void MyCreateDirectoryEx(CString strPath)
{
 //如果存在\结束符号,去掉
 if(strPath.Right(1)=="\\")
strPath=strPath.Left(strPath.GetLength()-1); 
 // 如果要建立的文件已经存在,返回
 if(GetFileAttributes(strPath)!=-1) 
return;
 int nFound = strPath.ReverseFind('\\');
 MyCreateDirectoryEx(strPath.Left(nFound)); 
 CreateDirectory(strPath,NULL); 
 return ;
}
(发表于2002-10-18 23:06:00)

知秋一叶:hao
(发表于2003-9-3 13:27:00)

phinecos:有个bug,应该修改如下:
bool DirectoryHelper::CreateDirectroy(const wchar_t *dir)
{
list dirStack;

wstring tmp = dir;

dirStack.push_front(tmp);

int i = tmp.rfind(L"\\");

//从后面往前找"\\",检查是否存在目录。
while(i>0)
{
tmp = tmp.substr(0,i);
if(isDirExists(tmp.c_str()))break;
i = tmp.rfind(L"\\",i);
if(i>=0)
dirStack.push_front(tmp);

}

if(i<0 && (L":" != tmp.substr(tmp.length()-1,1)))
return false; //错误的目录格式

try
{
for(list::iterator it=dirStack.begin();
it!=dirStack.end();it++)
{
::CreateDirectory((*it).c_str(),NULL);
}
}
catch(...)
{
return false;
}

return true;
}
(发表于2008-3-6 11:31:00)

..........................................................................
--------------------next---------------------

阅读(205) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~