This is for a Windows-only program so portable code is not an issue.
I need simply:
bool DoesFileExist( LPWSTR lpszFilename )
{
// ...
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are two common ways to do this in Windows code. GetFileAttributes, and CreateFile,
This will tell you a file exists, but but it won’t tell you whether you have access to it. for that you need to use CreateFile.
But remember, that even if you get back true from one of these calls, the file could still not exist by the time you get around to opening it. Many times it’s best to just behave as if the file exists and gracefully handle the errors when it doesn’t.