如何判断文件是否存在?

来源:互联网 发布:十一选五遗漏数据 编辑:程序博客网 时间:2024/04/30 01:29
#include <sys/stat.h>
#include <io.h>

bool FileExist(const char* FileName)
{
    struct stat my_stat;
    return (stat(FileName, &my_stat) == 0);
}


bool IsDirectory(const char* FileName)
{
    struct stat my_stat;
    if (stat(FileName, &my_stat) != 0) return false;
    return ((my_stat.st_mode & S_IFDIR) != 0);
}