The following function checks if a file exists.
#define WIN32_LEAN_AND_MEAN #include <windows.h> #ifndef INVALID_FILE_ATTRIBUTES #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) #endif /* Returns TRUE if filename is a file or FALSE if filename is either NULL, empty or it's a directory */ BOOL IsFile(const char *filename) { DWORD dRet; if (!filename || filename[0] == '\0') return FALSE; dRet = GetFileAttributes(filename); if (dRet == INVALID_FILE_ATTRIBUTES) return FALSE; return (BOOL) !(dRet & FILE_ATTRIBUTE_DIRECTORY); }