Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  C语言  >  正文 C语言判断目录是否存在的例子

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

发布时间:2018-09-24   编辑:www.jquerycn.cn
jquery中文网为您提供C语言判断目录是否存在的例子等资源,欢迎您收藏本站,我们将为您提供最新的C语言判断目录是否存在的例子资源
要判断目录存在这个问题对于php或asp非常的简单一行代码搞定,但对于c语言来讲相对比较复杂了,下面看个例子。

例子

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

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]);
}

您可能感兴趣的文章:
C语言判断目录是否存在的例子
学习linux shell中 if else以及大于、小于、等于逻辑表达式
php用于判断文件是否存在、是否可读、目录是否存在的代码
shell条件测试之test语句的用法
批处理的语句结构
asp.net Directory.Exists判断文件夹是否存在代码
shell 条件判断的基本语法与实例
使用php判断文件是否存在、是否可读、目录是否存在
php 判断文件存在与否的函数选择(file_exists or is_file)
C 语言实例

[关闭]