Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if directory is exists

Status
Not open for further replies.

kayDelphi

Programmer
Mar 15, 2010
7
US
Hi all,
Please i needs some help to check if directory is exists in native C++/win32. I have seen many samples on the web but im not sure which one is the right one. I read about CreateDirectory, GetFileAttributes and SHGetFileInfo and other methods. I will appreciate any suggestions with sample code snippet

Thanks
kay
 
Thanks, i found the solution to check it
LPTSTR path = "C:\\test";
SHFILEINFO shFileInfo;
if (SHGetFileInfo((LPCSTR)path, 0, &shFileInfo, sizeof(SHFILEINFO), SHGFI_TYPENAME) != 0)
{
MessageBoxA(NULL, "Exists", "DIRECTORY", MB_OK);

}
else
{
MessageBoxA(NULL, "NOT FOUND", "DIRECTORY", MB_OK);
}
kay
 
More straightforward approach:
Code:
DWORD rc = ::GetFileAttributes(path);
bool isdir = (rc != (DWORD)0xFFFFFFFF &&
             (rc & FILE_ATTRIBUTE_DIRECTORY) != 0);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top