标准c判断目录是否存在

来源:互联网 发布:淘宝qq群推广号 编辑:程序博客网 时间:2024/04/29 08:50

#include <io.h> // For access(). #include <sys/types.h> // For stat(). #include <sys/stat.h> // For stat(). #include <iostream> #include <string> using namespace std; string strPath; cout << "Enter directory to check: "; cin >> strPath; if ( access( strPath.c_str(), 0 ) == 0 ) { struct stat status; stat( strPath.c_str(), &status ); if ( status.st_mode & S_IFDIR ) { cout << "The directory exists." << endl; } else { cout << "The path you entered is a file." << endl; } } else { cout << "Path doesn't exist." << endl; }