PathFileExists 函数可以用来查看一个文件或文件夹是否存在。
在使用这个函数时,要注意两点:
1. 加入#include <shlwapi.h>.
2. 在project(工程)->setting(设置)->link(连接)下objiect/library modules(对象/库模块)中加入shlwapi.lib.
使用例子:
(1).判断文件
CString strFile = "E://darcy//example//test.txt"
if (PathFileExists(strFile) == 1)
{
MessageBox("该文件存在", "操作结果", MB_ICONQUESTION);
}
(2).判断文件夹
CString strPath = "E://darcy//example"
if (PathFileExists(strPath) == 1)
{
MessageBox("该文件夹存在", "操作结果", MB_ICONQUESTION);
}