bool CFileHelper::createDirs(const char* szDir) { if (szDir == NULL) { ScutLog("createDirs Error %s %d", szDir, __LINE__); return false; } const char *pBegin = szDir; const char *pend = szDir; do { char szBuf[MAX_PATH]; pend = strchr(pend,FILE_SEP); if (NULL != pend) { ++pend; int nSize = pend-pBegin; memcpy(szBuf,pBegin,nSize); szBuf[nSize] = '\0'; std::string dir; dir = szBuf; if (!isDirExists(dir.c_str())) { if(!createDir(dir.c_str())) { ScutLog("createDirs Error %s %d", szDir, __LINE__); break; } } } } while (NULL != pend); return true; }
// Parametre olarak verilen path yapisinda dolasarak olmayan directory'leri olusturur // ve bir alt dizine inerek ayni isleme devam eder. void checkFolderStructure(char *directory, int *nDir_fd){ char *dir; struct stat st; char *segFaultCheck = "."; // Verilen directory (path), "/" karakterine gore split edilir ve path'deki ilk // directory elde edilir. if (strcmp(directory, segFaultCheck) != 0){ dir = strtok(directory, "/"); // dir, newPath degiskenine append edilir. concatWithCurrDir(dir); chdir(newPath); while (dir != NULL) { if (chdir(newPath) == 0) { ; // bir sey yapma } else { if (isDirExists(st, newPath)) { printf("Error when checking directory: %s\n", newPath); perror("Error"); exit(1); } else { *nDir_fd = mkdir(newPath, 0777); // klasor olusturulurken bir hata meydana gelmisse if (*nDir_fd == -1) { // olusan hata, "klasor mevcut" hatasindan baska bir hata ise // programdan cik. if (errno != EEXIST) { printf("Error when creating directory %s\n", newPath); perror("Error"); exit(1); } // klasor mevcut hatasi ise birsey yapmaya gerek yok } // klasor basariyla olusturuldu } } // bir sonraki klasor adini parse et dir = strtok(NULL, "/"); // parse isleminde sona gelinmemisse isleme devam et if (dir != NULL) concatWithCurrDir(dir); else // sona gelinmisse donguyu sonlandir break; } } }