Solved

how can I know if file is exist?

Posted on 2001-06-25
5
167 Views
Last Modified: 2013-11-20
hello experts,

is ther a way to check that particular file exist in the working path?
0
Comment
Question by:kobibass
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6224491
Hi!
you can use
access C runtime, for example:
     if (access(lpszFileName, 00) != -1)
          {
// file exist
}
0
 
LVL 32

Expert Comment

by:jhance
ID: 6224500
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
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6224700
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
 
LVL 32

Expert Comment

by:jhance
ID: 6224822
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
 
LVL 86

Expert Comment

by:jkr
ID: 6224911
>>But either will get you the same result....

Youi're of course right about this, jhance ;o)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question