【发布时间】:2014-12-27 07:14:36
【问题描述】:
我想在新目录中创建一个新目录。像这样的:
#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的权限和所有权是什么?你是哪个用户运行程序的? -
以非 root 用户身份运行。我将模式指定为 0777。它在代码中。
-
目录
testabc1是否存在? -
@MichaelWalz 不,它没有。
标签: c linux operating-system filesystems mkdir