3 out of 7 rated this helpful - Rate this topic

PathIsDirectory function

Applies to: desktop apps only

Verifies that a path is a valid directory.

Syntax

BOOL PathIsDirectory(
  __in  LPCTSTR pszPath
);

Parameters

pszPath [in]

Type: LPCTSTR

A pointer to a null-terminated string of maximum length MAX_PATH that contains the path to verify.

Return value

Type: BOOL

Returns (BOOL)FILE_ATTRIBUTE_DIRECTORY if the path is a valid directory; otherwise, FALSE.

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP

Minimum supported server

Windows 2000 Server

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 4.71 or later)

Unicode and ANSI names

PathIsDirectoryW (Unicode) and PathIsDirectoryA (ANSI)

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Never test against true/TRUE - test against !false/!FALSE
It is very poor coding practice to do this: "bool bResult = (bSomeBool == true);" First, if necessary define your own const value or definition of "true" as being "not false" (note that those definitions or consts are already provided in every coding environment I know of). But in all cases the example above should have been coded as "bool bResult = (bSomeBool != false);" Most mature functions/methods take advantage of the fact a bool is 8 bits (and a BOOL is 32 bits) to pass back extra information in the return code, so you need to be prepared for the fact that anyvalue not expressly false must be assumed to be true.
Description of "Return Value" is wrong.

The description of "Return Value" is wrong.

The correct wording should read:
Returns FILE_ATTRIBUTE_DIRECTORY if the path is a valid directory, or FALSE otherwise.

FALSE = 0
FILE_ATTRIBUTE_DIRECTORY = 16

Broken return code

It seems to be either FALSE (0) or a non-zero (0x10) value, if(PathIsDirectory() == TRUE) does not eval to true, surprisingly.

Tested it under w7 just now.

This function performs IO as it needs to query the file in question for its attributes

Locally this is usually fast, but over the network this can be slow. Don't make this call on UI threads, instead call this function in background worker threads.