Login dark

title: 建立多级目录的函数源代码
author: Love02xp
date: 2018-01-28 02:40:48
category: [编程代码]
tags: [VC6,编程]
draft: false
cover:
preview:



##### [阅读原文]()
方法一:
#include   <imagehlp.h> 
link   imagehlp.lib 

BOOL   MakeSureDirectoryPathExists(PCSTR DirPath); 


<!--more-->




DirPath   must   end   with   a   backslash   (\)   character 

for   example: 
MakeSureDirectoryPathExists( "c:\\a\\b\\ ");






方法二:
函数说明:
  入口:要创建的目录,CString类型
  出口:BOOL类型,true 成功,false 失败。
  代码如下:

  CreateMuliteCategory(CString FilePath)
  {
  CString Tempstr,dir;
  Tempstr="";
  int index=Tempstr.Find(’’);
  while(!SetCurrentDirectory(FilePath))//?D?????t?Dê?·?′??ú
  {
  index ++;
  while(’’ != FilePath.GetAt(index))
  {
  index ++;
  }
  CString s;
  s.Format("%d",index);
  Tempstr = FilePath.Left(index);//μ?μ?2?·??·??
  CreateDirectory(Tempstr,NULL);
  }
  if(!SetCurrentDirectory(FilePath))
  {
  MessageBox("???t?D′′?¨ê§°ü!");
  return false;
  }
  return true;
  }
  说明:函数没有采用异常处理,可以根据需要自行修改。此函数只是提供了一个解决办法。