gpt4 book ai didi

c - 给定的文件参数是否是目录。 C

转载 作者:太空宇宙 更新时间:2023-11-04 07:24:24 26 4
gpt4 key购买 nike

我正在寻找一个安静的代码来检查我传递给我的程序的参数是否是一个目录。到目前为止,我发现了这个:

#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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com