我正在寻找一个安静的代码来检查我传递给我的程序的参数是否是一个目录。到目前为止,我发现了这个:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
struct stat buf;
stat(argv[1],&buf);
exit(0);
}
但它并没有真正帮助我。
最佳答案
使用:
if(S_ISDIR(buf.st_mode))
printf(" Its a directoy\n");
else
printf("Its a file\n");
在 stat(argv[1],&buf);
调用之后
关于c - 给定的文件参数是否是目录。 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19464571/