#include <direct.h> #include <string> void main() { string targetPath = "c:\\1\\2\\3\\"; CheckTargetPath(targetPath); } //if the directory is not existing, creat it void CheckTargetPath(string targetPath) { //Log &log = Log::getLog("main", "CheckTargetPath"); int e_pos = targetPath.length(); int f_pos = targetPath.find("\\",0); string subdir; do { e_pos = targetPath.find("\\",f_pos+2); if(e_pos != -1) { subdir = targetPath.substr(0,e_pos); if(_mkdir(subdir.c_str())==0) // log.debug( "creat success %s",subdir.c_str()); // else log.debug("creat fail %s",subdir.c_str()); } f_pos = e_pos; }while(f_pos!=-1); } |
|