cls

建立多级目录

Posted on 2010-01-05 23:00 赏心悦目 阅读(40) 评论(0)  编辑  收藏
 1#include "stdafx.h"
 2#include <string>
 3#include <afx.h>
 4using namespace std;
 5
 6//创建多级目录
 7BOOL createMultipleCategory(string categoryPath)
 8{
 9    if(categoryPath.size == 0 )
10        return false;
11
12    // 检验路径是否以"\\"结尾,若不是,则添加
13    int length = categoryPath.size();
14    if( (categoryPath[length-2]!='\\'&& (categoryPath[length-1]!='\\')){
15        categoryPath += "\\";
16    }

17    
18    string dir;
19    int begin = 0 ;
20    int end;
21
22    // 考虑路径是绝对路径的情况
23    if( (end=categoryPath.find(":",begin)) != string::npos ){
24        begin = end+2;
25    }
 
26
27    end = categoryPath.find("\\",begin);
28    while(end != string::npos){
29        dir = categoryPath.substr(0,end);
30        CreateDirectory(dir.c_str(),NULL);
31        begin = end +2;
32        end = categoryPath.find("\\",begin);
33    }

34    return true;
35}

36
37int main(int argc, char* argv[])
38{
39    BOOL suc = createMultipleCategory("adsds\\test");
40    printf("%d\n",suc);
41    printf("Hello World!\n");
42    return 0;
43}

只有注册用户登录后才能发表评论。
网站导航: