Original Post
in c++ using simple i/o, how can i tell (given a file name) if the file exists?
[edited by - Mulligan on March 8, 2004 1:42:00 AM]
if(ifstream("fileName"))
cout << "exists!";
quote:
Original post by sas
bool exists(const string& fileName)
{
bool returnValue = false;
DWORD attrib = GetFileAttributes(fileName.c_str());
if (attrib != 0xFFFFFFFF)
{
returnValue = true;
}
return returnValue;
}
quote:
Original post by Arild Finesquote:
Original post by sas
bool exists(const string& fileName)
{
bool returnValue = false;
DWORD attrib = GetFileAttributes(fileName.c_str());
if (attrib != 0xFFFFFFFF)
{
returnValue = true;
}
return returnValue;
}
Would you by any chance have a programming teacher that smacks you over the head if you have more than one exit point from a function?
bool FileExists( const char* FileName )
{
FILE* fp = NULL;
//will not work if you do not have read permissions
//to the file, but if you don''t have read, it
//may as well not exist to begin with.
fp = fopen( FileName, "rb" );
if( fp != NULL )
{
fclose( fp );
return true;
}
return false;
}
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more