Solved

how can I know if file is exist?

Posted on 2001-06-25
5
174 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 163
How to know only "File created" with EventLog 3 35
mapAB Challlenge 35 160
how to split multiple lines delimiter : 8 112
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.

830 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