Solved

how can I know if file is exist?

Posted on 2001-06-25
5
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to determine file rename from EventLog ? 2 62
bigDiff challenge 17 142
post4 challenge 28 121
Making an alias 7 121
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

732 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