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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if a file exists

Status
Not open for further replies.

Maurader

Technical User
May 8, 2002
59
CA
I want to open a stream for file output. How do I check if the file exists? If it exists, I want to popup a dialog box asking if the user wants to overwrite...

thanks!
 
First, try to open the stream for input. If that fails, then your file doesn't exist.
 
Try this:

bool fExist( char* filename )
{
WIN32_FIND_DATA file;
HANDLE hFile;
if (( hFile = FindFirstFile( filename,&file ))
== INVALID_HANDLE_VALUE )
{
return false;
}
return true;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top