Linux下递归创建目录,废话不多说,上源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
int CreateDir(const char *sPathName) { char DirName[256]; strcpy(DirName, sPathName); int i,len = strlen(DirName); if(DirName[len-1]!='/') strcat(DirName, "/"); len = strlen(DirName); for(i=1; i<len; i++) { if(DirName[i]=='/') { DirName[i] = 0; if( access(DirName, NULL)!=0 ) { if(mkdir(DirName, 0755)==-1) { perror("mkdir error"); return -1; } } DirName[i] = '/'; } } return 0; } |
发表评论
要发表评论,您必须先登录。