How can we check if a file Exists or not using Win32 program?

How can we check if a file Exists or not using a Win32 program? I am working for a Windows Mobile App.


Use GetFileAttributes to check that the file system object exists and that it is not a directory.

BOOL FileExists(LPCTSTR szPath)
{
  DWORD dwAttrib = GetFileAttributes(szPath);

  return (dwAttrib != INVALID_FILE_ATTRIBUTES && 
         !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}

Copied from How do you check if a directory exists on Windows in C?


You can make use of the function GetFileAttributes. It returns 0xFFFFFFFF if the file does not exist.