Dave's Brain

Browse - programming tips - win32 is directory folder

Date: 2011jan21
Platform: win32
Language: C/C++

Q.  How can I check that a path is a directory/folder?

A.  Here's a small function that does it.

	BOOL IsDir(LPCSTR szDir)
	{
		DWORD dwAttrib;
	
		if ((dAttrib = GetFileAttributesW(szDir)) == 0xFFFFFFFF) return FALSE;
		return (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
	}

	void ExampleUse()
	{
		if (IsDir("C:\\Windows"))
		{
			printf("c:\\Windows exists and is a folder\n");
		}
		else
		{
			printf("c:\\Windows isn't a 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: