Linux 拨号vps windows公众号手机端

MFC查找指定文件是否存在

lewis 6年前 (2019-01-10) 阅读数 8 #程序编程
文章标签 MFC

您可以使用CFileFind类来查找指定文件是否存在。以下是一个示例代码:

#include <afx.h>
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\n");
}
else
{
printf("File does not exist\n");
}
return 0;
}

在上述代码中,IsFileExists函数接受一个LPCTSTR参数表示文件路径,然后使用CFileFind的FindFile方法尝试查找指定文件。如果返回值为true,则表示文件存在,否则表示文件不存在。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门