Browse - Programming Tips - How can I see if a path is a folder ?

Date: 2009jul16
Platform: win32
Language: C/C++
Keywords: check, directory, dir

Q.  How can I see if a path is a folder ?

A.  Here's an easy function for that:

BOOL IsDir(LPCSTR szDir) { DWORD dwAttrib; if ((dwAttrib = GetFileAttributes(szDir)) == 0xFFFFFFFF) return FALSE; return dwAttrib & FILE_ATTRIBUTE_DIRECTORY; }
ExampleUse() { if (IsDir("c:\\Documents and Settings")) { printf("You have a D&S folder\n"); } else { printf("You do NOT have a D&S folder\n"); } }