C语言判断目录是否存在的例子

作者:袖梨 2022-06-25

例子

#include
#include
#include
#include
#include

int main(int argc,char *argv[])
{
        struct stat filestat;
        if(argc!=2)
        {
                printf("Usage ./a.out argv1\n");
                exit(-1);
        }
        if(stat(argv[1],&filestat)!=0)
        {
                perror(argv[1]);
                return -1;
        }
        if(S_ISDIR(filestat.st_mode))
                printf("%s is dir \n",argv[1]);
        else
                printf("%s is not dir\n",argv[1]);
}

相关文章

精彩推荐