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,则表示文件存在,否则表示文件不存在。
版权声明
本文仅代表作者观点,不代表米安网络立场。
上一篇:jsp如何上传云主机 下一篇:如何使用ggplot2进行网络可视化
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。