how can I know if file is exist?

hello experts,

is ther a way to check that particular file exist in the working path?
kobibassAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
The 'official' Win32 way would be to

if ( -1 == GetFileAttributes ( "drive:\\path\\file.ext"))
{
 // doesn't exist
}
else
{
 // exists
}

Note that this way doesn't require to open the file.
0
 
migelCommented:
Hi!
you can use
access C runtime, for example:
     if (access(lpszFileName, 00) != -1)
          {
// file exist
}
0
 
jhanceCommented:
Use:

CFile::GetStatus()

static BOOL PASCAL GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );

Just pass it the name of the file and a reference to a CFileStatus struct.  If the call fails it's due to the the file not being there or not being accessible to you.
0
 
jhanceCommented:
Well, this is the MFC topic area so I'd say the "official" MFC method is to use CFile::GetStatus().  ;-)

But either will get you the same result....
0
 
jkrCommented:
>>But either will get you the same result....

Youi're of course right about this, jhance ;o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.