PDA

Click to See Complete Forum and Search --> : Check if directory exists - c++


silentthread
Dec 17th, 2007, 04:48 PM
Probably the most painfull part about getting this together was the fact that my compiler did not understand INVALID_FILE_ATTRIBUTES, so I had to do a cast thingy and check for ((DWORD)-1).

Also, I did not remember that c++ is sensitive to backslashes, so...
c:\test
should really be
c:\\test

Enjoy.....

Prototype....
bool FolderExists(string file);//function prototype

A sample call....
bool folderexist;
folderexist=FolderExists("c:\\test2");
cout << folderexist;

Function definition....
bool FolderExists(string file)
{
DWORD returnvalue;
returnvalue = GetFileAttributes(file.c_str());
if(returnvalue == ((DWORD)-1))
{
return false;
}
else
{ return true;
}
}