码龄10年
暂无认证
43339
访问
1
等级
8
获赞
3
评论
热门文章
-
一.某岛之人物对象及其加密函数解析
2653
-
一.《传奇M》装备栏遍历的突破口
2281
-
二.某龙端游中LUA的分析和调用
2035
-
一.窗口坐标与屏幕坐标
1756
-
一.《轩辕传奇》周围遍历之二叉树
1754
最新评论
-
20240228阿⑤
积分乍获得
-
20231124ziher
666
-
20230909八月老师
什麼時候發佈易語言支持庫呢
一.《WIN32》判断文件夹是否存在
Heart
2023-08-29 09:08:48 发布
387
分类专栏: 开发技术 文章标签: 判断文件夹是否存在
判断文件代码:
///////////////////////////////////////////////////////////////////////Win102
#ifdef WIN32
#include //C (Windows) access
#else
#include //C (Linux) access
#endif
///////////////////////////////////////////////////////////////////////C++
#include //C++ fstream
///////////////////////////////////////////////////////////////////////WIN32
#ifdef WIN32
#include //Windows API FindFirstFile
#include #pragma comment(lib, "shlwapi.lib") //Windows API PathFileExists
#endif
///////////////////////////////////////////////////////////////////////boost
#include //boost
using namespace std;
int main()
{
char file_name[] = "C://迪大学院.txt";
///////////////////////////////////////////////////////////////////////
//C run in windows and linux
if ( 0 == access(file_name, 0) ) cout<<"access(): file exist."<<endl;
else cout<<"access(): file not exist."<<endl;
///////////////////////////////////////////////////////////////////////
//C++ run in windows and linux
fstream fs;
fs.open(file_name, ios::in);
if (fs) cout<<"fstream: file exist."<<endl;
else cout<<"fstream: file not exist."<<endl;
fs.close();
///////////////////////////////////////////////////////////////////////
//Windows API run in windows
#ifdef WIN32
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(file_name, &wfd);
if ( INVALID_HANDLE_VALUE != hFind ) cout<<"FindFirstFile: file exist."<<endl;
else cout<<"FindFirstFile: file not exist."<<endl;
CloseHandle(hFind);
if ( PathFileExists(file_name) ) cout<<"PathFileExists: file exist."<<endl;
else cout<<"PathFileExists: file not exist."<<endl;
if ( INVALID_FILE_ATTRIBUTES != GetFileAttributes(file_name) ) cout<<"GetFileAttributes: file exist."<<endl;
else cout<<"GetFileAttributes: file not exist."<<endl;
if ( INVALID_HANDLE_VALUE != CreateFile(file_name, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL) ) cout<<"CreateFile: file exist."<<endl;
else cout<<"CreateFile: file not exist."<<endl;
#endif
///////////////////////////////////////////////////////////////////////
//boost run in windows and linux
boost::filesystem::path path_file(file_name);
if ( boost::filesystem::exists(path_file) &&
boost::filesystem::is_regular_file(path_file) ) cout<<"boost: file exist."<<endl;
else cout<<"boost: file not exist."<<endl;
return 0;
}判断文件夹代码:
////////////////////////////////////////////////////////////win32
#ifdef WIN32
#include //C (Windows) access
#else
#include //C (Linux) access
#endif
#ifdef WIN32
#include //Windows API FindFirstFile
#include #pragma comment(lib, "shlwapi.lib") //Windows API PathFileExists
#endif
////////////////////////////////////////////////////////////boost C++
#include //boost
using namespace std;
////////////////////////////////////////////////////////////
int main()
{
char file_name[] = "C:\\迪大学院\\";
///////////////////////////////////////////////////////////////////////
//C run in windows and linux
if ( 0 == access(file_name, 0) ) cout<<"access(): path exist."<<endl;
else cout<<"access(): path not exist."<<endl;
///////////////////////////////////////////////////////////////////////
//Windows API run in windows
#ifdef WIN32
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(file_name, &wfd);
if ( INVALID_HANDLE_VALUE != hFind && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) cout<<"FindFirstFile: path exist."<<endl;
else cout<<"FindFirstFile: path not exist."<<endl;
CloseHandle(hFind);
if ( PathFileExists(file_name) ) cout<<"PathFileExists: path exist."<<endl;
else cout<<"PathFileExists: path not exist."<<endl;
if ( INVALID_FILE_ATTRIBUTES != GetFileAttributes(file_name) ) cout<<"GetFileAttributes: path exist."<<endl;
else cout<<"GetFileAttributes: path not exist."<<endl;
#endif
///////////////////////////////////////////////////////////////////////
//boost run in windows and linux
boost::filesystem::path path_file(file_name);
if ( boost::filesystem::exists(path_file) && boost::filesystem::is_directory(path_file) ) cout<<"boost: path exist."<<endl;
else cout<<"boost: path not exist."<<endl;
return 0;
}比较:
网友评论
0条评论 0人参与
评论列表
0
0