#include <iostream>
#ifndef _WIN32
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#endif
using namespace std;
int IsFloderexit(const char* path)
{
DIR *dp;
if ((dp = opendir(path)) == NULL)
{
return 0;
}
closedir(dp);
return -1;
}
//-1是存在
int IsFileExist(const char* path)
{
return !access(path, F_OK);
}
int main()
{
int error = IsFloderexit("/home/freetds");
if (-1 == error)
{
cout << "the floder exit" << endl;
int errorFile = IsFileExist("/home/freetds/aclocal.m4");
if (-1 == error)
{
cout << "the file exit" << endl;
}
}
return 0;
}
c++判断本地目录或本地文件是否存在linux
猜你喜欢
转载自blog.csdn.net/mp295345033/article/details/50075005
今日推荐
周排行