新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

MFC查找指定文件是不是存在,mfc打开指定位置的文件

发布时间:2023-08-07 07:56:03

MFC查找指定文件是否是存在

您可使用CFileFind类来查找指定文件是否是存在。以下是一个示例代码:
```cpp
#include
bool IsFileExists(LPCTSTR filePath)
{
CFileFind fileFind;
return fileFind.FindFile(filePath);
}
int main()
{
LPCTSTR filePath = _T("C:\path\to\file.txt");
if (IsFileExists(filePath))
{
printf("File exists ");
}
else
{
printf("File does not exist ");
}
return 0;
}
```
在上述代码中,IsFileExists函数接受一个LPCTSTR参数表示文件路径,然后使用CFileFind的FindFile方法尝试查找指定文件。如果返回值为true,则表示文件存在,否则表示文件不存在。