2021-09-02 23:20:12 +02:00
|
|
|
extern int (*mkdir)(char*);
|
2010-10-17 21:50:55 +02:00
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
int cmd_mkdir(char dir[]) {
|
2021-09-02 23:20:12 +02:00
|
|
|
unsigned dir_len = strlen(dir);
|
|
|
|
if(!dir_len){
|
2021-06-12 23:34:41 +02:00
|
|
|
printf(CMD_MKDIR_USAGE);
|
|
|
|
return TRUE;
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-02 23:20:12 +02:00
|
|
|
char *temp = malloc(dir_len+3);
|
|
|
|
char *dir_path = strdup(dir);
|
|
|
|
ksys_bdfe_t *bdfe = malloc(sizeof(ksys_bdfe_t));
|
|
|
|
if(!dir_path || !temp || !bdfe){
|
2021-06-12 23:34:41 +02:00
|
|
|
return FALSE;
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
2021-09-02 23:20:12 +02:00
|
|
|
|
|
|
|
if(dir[0]=='/' || dir[0]=='\\'){
|
|
|
|
temp[0]='\0';
|
|
|
|
}else{
|
|
|
|
strcpy(temp,".");
|
2010-10-17 21:50:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-02 23:20:12 +02:00
|
|
|
char *pch = strtok(dir_path,"\\/");
|
|
|
|
|
|
|
|
while (pch != NULL){
|
|
|
|
strcat(temp, "/");
|
|
|
|
strcat(temp, pch);
|
|
|
|
if(_ksys_file_get_info(temp, bdfe)){
|
|
|
|
if(mkdir(temp)){
|
|
|
|
printf("\033[0;31;40m FAIL %s\n", temp);
|
|
|
|
}else {
|
|
|
|
printf("\033[0;32;40m OK %s\n", temp);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
printf("\033[0;33;40m EXIST %s\n", temp);
|
|
|
|
}
|
|
|
|
pch = strtok(NULL, "\\/");
|
|
|
|
}
|
|
|
|
printf("\033[0m");
|
|
|
|
free(bdfe);
|
|
|
|
free(dir_path);
|
|
|
|
free(temp);
|
|
|
|
return TRUE;
|
|
|
|
}
|