This shows you the differences between two versions of the page.
— |
check_file_existence [2008/06/10 23:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Check the file existence ====== | ||
+ | The following function checks if a file exists. | ||
+ | |||
+ | <code c>#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); | ||
+ | }</code> |