vc递归创建文件夹

 1 void  CreateDir(const string& strPath)
 2 {
 3     if (PathFileExists(strPath.c_str()))
 4     {
 5         return;
 6     }
 7 
 8     size_t sPrePos = 0;
 9     string strTmp = "";
10     size_t sPos = strPath.find('\\');
11     if (sPos == string::npos)
12     {
13         return;
14     }
15 
16     strTmp = strPath.substr(0, sPos + 1);
17     if ( !PathFileExists( strTmp.c_str() ) )
18     {
19         return;
20     }
21 
22     sPrePos = sPos + 1;
23     sPos = strPath.find('\\', sPrePos);
24     while (sPos != string::npos)
25     {
26         strTmp = strPath.substr(0, sPos);
27         if (!PathFileExists(strTmp.c_str()))
28         {
29             CreateDirectory(strTmp.c_str(), NULL);
30         }
31 
32         sPrePos = sPos + 1;
33         sPos = strPath.find('\\', sPrePos);
34     }
35 
36     if (!PathFileExists(strPath.c_str()))
37     {
38         CreateDirectory(strPath.c_str(), NULL);
39     }
40 
41 }

 

posted @ 2015-01-21 19:36  柳絮飘诗  阅读(1382)  评论(0编辑  收藏  举报