【问题标题】:Whether a given file argument is a directory or not. C给定的文件参数是否是目录。 C
【发布时间】:2013-10-19 09:37:32
【问题描述】:

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

#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);

}

但这并没有真正帮助我。

【问题讨论】:

  • 你应该说明为什么它对你没有帮助。否则对那些想回答你的人没有帮助。

标签: c directory argv argc


【解决方案1】:

用途:

if(S_ISDIR(buf.st_mode))
   printf(" Its a directoy\n");
else
   printf("Its a file\n");

stat(argv[1],&amp;buf); 通话后

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 2017-12-16
    • 2010-09-13
    • 2013-07-09
    • 2019-08-28
    • 2019-02-24
    • 2014-06-21
    相关资源
    最近更新 更多