1. 程式人生 > >C++ mkdir 建立多級資料夾目錄

C++ mkdir 建立多級資料夾目錄

mkdir函式的標頭檔案:

#include <direct.h>

用for迴圈依次建立:

    char *strDirPath="D:\\test\\test1\\test2\\";
    if (strlen(strDirPath)>MAX_PATH)
    {
        return;
    }
    int ipathLength=strlen(strDirPath);
    int ileaveLength=0;
    int iCreatedLength=0;
    char szPathTemp[MAX_PATH]={0};
    for
(int i=0;(NULL!=strchr(strDirPath+iCreatedLength,'\\'));i++) { ileaveLength=strlen(strchr(strDirPath+iCreatedLength,'\\'))-1; iCreatedLength=ipathLength-ileaveLength; strncpy(szPathTemp,strDirPath,iCreatedLength); mkdir(szPathTemp); } if (iCreatedLength<ipathLength) { mkdir(strDirPath); }