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 语言实例