c++判断本地目录或本地文件是否存在linux
2015-11-27 21:17
633 查看
#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; }
相关文章推荐
- Linux socket 初步
- 使用C++实现JNI接口需要注意的事项
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- 关于指针的一些事情
- Scientific Linux 5.5 图形安装教程
- 基于 Linux 集群环境上 GPFS 的问题诊断