Dave's Brain

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"); } }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.