Tuesday, February 3, 2009

[VC++] PathIsDirectory() PathIsDirectoryEmpty() PathIsExe() and more...

Let me call your attention to some interesting functions available for ease your job while handling various file/directory paths.

PathIsDirectory()
As the name suggest it will check given path is a directory or not (and return TRUE or FALSE respectively). See the below sample code,
    if( PathIsDirectory( "C:\\Windows" ))
{
// Yes given path is a directory
}
else
{
// Not a directory
}
PathIsDirectoryEmpty()
As the name suggest it will check whether the given directory path is empty.
    if( PathIsDirectoryEmpty( "C:\\temp" ))
{
// Yes given directory is empty
}
else
{
// Not an empty directory
}
PathIsExe()
As the name suggest it will check whether the given path is a path to any of .cmd, .bat, .pif, .scf, .exe, .com, or .scrfile
    if( PathIsExe( L"C:\\WINDOWS\\system32\\autochk.exe" ))
{
// Yes given path is an executable file
}
else
{
// Not an executable file
}
There are more similar functions available please refer MSDN if needed,
PathIsContentType()
PathIsFileSpec()
PathIsHTMLFile()
PathIsLFNFileSpec()
PathIsNetworkPath()
PathIsPrefix()
PathIsRelative()
PathIsRoot()
PathIsSameRoot()
PathIsSlow()
PathIsSystemFolder()
PathIsUNC ()
PathIsUNCServer()
PathIsUNCServerShare()
PathIsURL()

No comments: