Dave's Brain

Browse - programming tips - win32 is path a folder or directory

Date: 2009jul16
Platform: win32
Language: C/C++

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");
	}
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: