vc创建多级目录

void CreateAllDirectories(CString strDir)
{
 //remove ending / if exists
 if(strDir.Right(1)=="\\")
  strDir=strDir.Left(strDir.GetLength()-1); 

// base case . . .if directory exists
 if(GetFileAttributes(strDir)!=-1) 
  return;

 // recursive call, one less directory
 int nFound = strDir.ReverseFind('\\');
 CreateAllDirectories(strDir.Left(nFound)); 

 // actual work
 CreateDirectory(strDir,NULL); 
}
posted @ 2011-06-15 19:13  傲衣华少  阅读(316)  评论(0编辑  收藏  举报