判断文件、文件夹是否存在

BOOL TPubTools::FolderExist(const CString &strPath)
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
BOOL bRet = FALSE;

hFind = FindFirstFile(strPath, &wfd);

if (hFind != INVALID_HANDLE_VALUE)
{
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
bRet = TRUE;
}

FindClose(hFind);
}

return bRet;
}

 

BOOL TPubTools::FileExist(const CString &strPath)
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
BOOL bRet = FALSE;

hFind = FindFirstFile(strPath, &wfd);

if (hFind != INVALID_HANDLE_VALUE)
{
if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
bRet = TRUE;
}

FindClose(hFind);
}

return bRet;
}

原文地址:https://www.cnblogs.com/huhu0013/p/4428114.html