User Tools

Site Tools


check_file_existence

Check the file existence

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);
}
check_file_existence.txt · Last modified: 2008/06/10 23:05 by crl