Projects > cpp > Issues > Bug #4711

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

[win32] Passing empty string to FileUtils::isFileExist may also return true

Bug #4711 [Closed]
dumganhar 2014-04-08 07:24 . Updated over 2 years ago

It's because GetFileAttributesW not only check whether file exists but also check directory exists.
FIX IT BY

1
2
3
4
    DWORD attr = GetFileAttributesW(utf16Buf);
    if(attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
        return false;   //  not a file
    return true;
shauket 2014-04-08 11:49

Use this one.

WIN32_FILE_ATTRIBUTE_DATA data;
GET_FILEEX_INFO_LEVELS fInfoLevelId = GetFileExInfoStandard;

std::string s_str = string(pszPath);
std::wstring wid_str = std::wstring(s_str.begin(), s_str.end());
const wchar_t * xyz1 = wid_str.c_str();
GetFileAttributesEx(xyz1, fInfoLevelId, &data);
DWORD x = data.dwFileAttributes;
if ( x == 16 || x == 32)//16 for dir 32 for file
{
return true;
}
return false;

dumganhar 2014-04-09 02:10
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:9ae5d64b93207ed4f2af1f5c88f2590bbd149329.

Atom PDF

Status:Closed
Start date:2014-04-08
Priority:Normal
Due date:
Assignee:dumganhar
% Done:

100%

Category:windows
Target version:3.0-rc2

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.