Linux下c语言创建文件目录
摘自:https://blog.csdn.net/chanshibing/article/details/80048495
1 #include<stdio.h> 2 #include <sys/stat.h> 3 #include <sys/types.h> 4 int CreateDir(const char *sPathName) 5 { 6 char DirName[256]; 7 strcpy(DirName, sPathName); 8 int i,len = strlen(DirName); 9 for(i=1; i<len; i++) 10 { 11 if(DirName[i]=='/') 12 { 13 DirName[i] = 0; 14 if(access(DirName, NULL)!=0) 15 { 16 if(mkdir(DirName, 0755)==-1) 17 { 18 printf("mkdir error\n"); 19 return -1; 20 } 21 } 22 DirName[i] = '/'; 23 24 } 25 } 26 27 return 0; 28 } 29 30 void main(){ 31 CreateDir("/home/superbing/test/2/"); 32 }