confirm if a file exists

 

Before opening  a file, its better to confirm if it exists.

    WIN32_FIND_DATA  fd;

    HANDLE hFile = ::FindFirstFile( fName, &fd );

 

    if ( hFile == INVALID_HANDLE_VALUE )

    {

       // file must not exist -- warn user

 

       CString sMessage;

       sMessage.Format( "Could not find specified file/n/"%s/"", fName );

      

       ::MessageBox( NULL, sMessage, "Could Not Find File",

           MB_OK | MB_ICONEXCLAMATION );

 

       ::FindClose( hFile );

       return;

 

    }

 

    ::FindClose( hFile );

你可能感兴趣的:(user,File,null)