User Tools

Site Tools


check_directory_existence

Check directory existence

The following code checks for the existence of a directory on the filesystem.

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
 
#ifndef INVALID_FILE_ATTRIBUTES
#define INVALID_FILE_ATTRIBUTES	((DWORD)-1)
#endif
 
/*
    Returns TRUE if filename parameter is a directory
    or FALSE if filename is either NULL or a file
*/
 
BOOL IsDir(const char *filename)
{
	DWORD dwAttrs; 
 
	dwAttrs = GetFileAttributes(filename);
	if (dwAttrs == INVALID_FILE_ATTRIBUTES)
		return FALSE;
 
	return (BOOL) (dwAttrs & FILE_ATTRIBUTE_DIRECTORY);
}
check_directory_existence.txt · Last modified: 2008/06/10 23:04 by crl