【发布时间】:2017-11-11 20:52:44
【问题描述】:
所以我正在处理目录遍历,我无法让 opendir 按我想要的方式工作。它总是无法打开我发送它的目录,它给出了一些未知的错误。我通常会传入 argv[1],但我放弃了,刚开始硬编码路径。
char *dest = NULL;
char *filePath = ".";
char *newPath = NULL;
DIR *dirp;
struct dirent *dp;
int errno;
dirp = opendir("/home/cs429/Desktop/test");
struct stat path_stat;
if(dirp == NULL);
{
// Error Handling
fprintf(stderr, "Error failed to open input directory -%s\n",strerror(errno) );
return 1;
}
有人知道我可以做些什么来获得 NULL 吗?我也在 gdb 中得到了这个: ../sysdeps/posix/opendir.c: 没有这样的文件或目录。
【问题讨论】:
-
文件夹是否存在?当您在终端中键入
cd /home/cs429/Desktop/test时会发生什么。检查路径的大小写。 -
请启用所有警告。这是 gcc 或 clang 检测到的。