Changed: Compare GetFileAttributes with INVALID_FILE_ATTRIBUTES to check if attributes are valid

This commit is contained in:
kervala 2010-09-27 14:40:21 +02:00
parent 637058962c
commit af00aa2b6f
3 changed files with 6 additions and 4 deletions

View file

@ -1747,7 +1747,7 @@ bool CFile::isDirectory (const string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
DWORD res = GetFileAttributes(filename.c_str()); DWORD res = GetFileAttributes(filename.c_str());
if (res == ~0U) if (res == INVALID_FILE_ATTRIBUTES)
{ {
// nlwarning ("PATH: '%s' is not a valid file or directory name", filename.c_str ()); // nlwarning ("PATH: '%s' is not a valid file or directory name", filename.c_str ());
return false; return false;
@ -1769,7 +1769,7 @@ bool CFile::isDirectory (const string &filename)
bool CFile::isExists (const string &filename) bool CFile::isExists (const string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return (GetFileAttributes(filename.c_str()) != ~0U); return (GetFileAttributes(filename.c_str()) != INVALID_FILE_ATTRIBUTES);
#else // NL_OS_WINDOWS #else // NL_OS_WINDOWS
struct stat buf; struct stat buf;
return stat (filename.c_str (), &buf) == 0; return stat (filename.c_str (), &buf) == 0;

View file

@ -136,7 +136,8 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
hFind = FindFirstFile (sFilter.c_str(), &findData); hFind = FindFirstFile (sFilter.c_str(), &findData);
while (hFind != INVALID_HANDLE_VALUE) while (hFind != INVALID_HANDLE_VALUE)
{ {
if (!(GetFileAttributes(findData.cFileName)&FILE_ATTRIBUTE_DIRECTORY)) DWORD res = GetFileAttributes(findData.cFileName);
if (res != INVALID_FILE_ATTRIBUTES && !(res&FILE_ATTRIBUTE_DIRECTORY))
{ {
if (bFullPath) if (bFullPath)
sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName); sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName);

View file

@ -66,7 +66,8 @@ void dir (const std::string &sFilter, std::vector<std::string> &sAllFiles, bool
hFind = FindFirstFile (sFilter.c_str(), &findData); hFind = FindFirstFile (sFilter.c_str(), &findData);
while (hFind != INVALID_HANDLE_VALUE) while (hFind != INVALID_HANDLE_VALUE)
{ {
if (!(GetFileAttributes(findData.cFileName)&FILE_ATTRIBUTE_DIRECTORY)) DWORD res = GetFileAttributes(findData.cFileName);
if (res != INVALID_FILE_ATTRIBUTES && !(res&FILE_ATTRIBUTE_DIRECTORY))
{ {
if (bFullPath) if (bFullPath)
sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName); sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName);