While reading configuration file, while reading some setting file, every where we’ve to check whether the file exists or not before opening and starts reading. The simple technique is to open the file by using file apis or to search for the file by using FindFirstFile(). Or is there any simple api to do so?


You can use the api – PathFileExists(). Check the following code snippet.

#include "shlwapi.h"
...
// File path.
CString csFile = _T( "C:\\Autumn Leaves.jpg");

if( PathFileExists( csFile ))
{
    // Yes! the file exists.
}


Don’t forget to add shlwapi.lib to your project settings. ;)


Targeted Audience – Beginners.