diff options
| author | Tannin <devnull@localhost> | 2015-01-11 11:16:04 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2015-01-11 11:16:04 +0100 |
| commit | 4d9795527d1b9fa77ceb0106f308a13f24e1fca4 (patch) | |
| tree | 4307e64854ec54bdff365f889421f0460818c310 /src | |
| parent | 9f09c30e0825c38dfa214f01cc381469b89e1c80 (diff) | |
different way to check for file existence
Diffstat (limited to 'src')
| -rw-r--r-- | src/shared/util.cpp | 24 | ||||
| -rw-r--r-- | src/shared/util.h | 1 |
2 files changed, 7 insertions, 18 deletions
diff --git a/src/shared/util.cpp b/src/shared/util.cpp index d284b517..1cbf088b 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -32,28 +32,16 @@ namespace MOShared { bool FileExists(const std::string &filename)
{
- WIN32_FIND_DATAA findData;
- ZeroMemory(&findData, sizeof(WIN32_FIND_DATAA));
- HANDLE search = ::FindFirstFileExA(filename.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, NULL, 0);
- if (search == INVALID_HANDLE_VALUE) {
- return false;
- } else {
- FindClose(search);
- return true;
- }
+ DWORD dwAttrib = ::GetFileAttributesA(filename.c_str());
+
+ return (dwAttrib != INVALID_FILE_ATTRIBUTES);
}
bool FileExists(const std::wstring &filename)
{
- WIN32_FIND_DATAW findData;
- ZeroMemory(&findData, sizeof(WIN32_FIND_DATAW));
- HANDLE search = ::FindFirstFileExW(filename.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, NULL, 0);
- if (search == INVALID_HANDLE_VALUE) {
- return false;
- } else {
- FindClose(search);
- return true;
- }
+ DWORD dwAttrib = ::GetFileAttributesW(filename.c_str());
+
+ return (dwAttrib != INVALID_FILE_ATTRIBUTES);
}
bool FileExists(const std::wstring &searchPath, const std::wstring &filename)
diff --git a/src/shared/util.h b/src/shared/util.h index 4af1fb1e..eba3fb3c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -30,6 +30,7 @@ namespace MOShared { static const int MAXPATH_UNICODE = 32767;
+/// Test if a file (or directory) by the specified name exists
bool FileExists(const std::string &filename);
bool FileExists(const std::wstring &filename);
|
