Gold mine of Visual C++ tricks!
How to check whether a file exists of not?
![]()
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.
| Print article | This entry was posted by Jijo Raj on July 3, 2008 at 6:21 pm, and is filed under Codeproject, Windows APIs. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 9 months ago
Doesn’t work, I got function not part of global namespace error
about 9 months ago
Hi Jim,
Its a Win32 api. Have a look at MSDN – http://msdn.microsoft.com/en-us/library/bb773584(VS.85).aspx.
If you still have problem, please give more details. Lets have a look at it.
Regards,
Jijo.