我想在一个新的目录内创建一个新目录。就像这样:
如果我删除testabc2,那么我就能够成功创建目录。为什么会这样呢?
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
int main() {
const char * path = "/home/abc/testabc1/testabc2" ;
mode_t mode = 0777;
if (mkdir(path, mode) == -1) {
// printf("Error occurred : %s ", strerror(errno));
perror("abc");
}
else {
printf("Directory created\n");
}
}
当我执行此操作时,出现以下错误:
abc: No such file or directory
如果我删除testabc2,那么我就能够成功创建目录。为什么会这样呢?
testabc2
的权限和所有权是什么?你是用哪个用户运行程序的? - Raptortestabc1
是否存在? - Jabberwocky