Solved

how can I know if file is exist?

Posted on 2001-06-25
5
146 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now