Re: File exist
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Tue, 18 Apr 2006 18:56:46 GMT
Mr John FO Evans <mijas@xxxxxxxxxxxxxxxxx> writes:
In article <76reh3xu85.ln2@xxxxxxxxxxxxxxxxxxxxxxx>, Flash Gordon[...]
<spam@xxxxxxxxxxxxxxxxxx> wrote:
It is not part of standard C. As I'm sure others have said in this
thread standard C does not provide any portable method to see if a file
exists. So you can be sure that any method you find goes beyond what
standard C provides.
What is wrong with attempting to open the file and if there is no error
closing it again? Surely this is standard 'C'?
Yes, but it only tells you whether you were able to open the file; it
doesn't necessarily tell you why. (And fopen() doesn't even
necessarily set errno to a meaningful value.)
On some systems, it might be possible to open a file in binary mode
but not in text mode, or vice versa.
In some cases, it's not even possible to determine whether a file
exists; you might not have permission to ask (e.g., if the file is in
a directory you don't have permission to read). Also, a file might
exist when you test it, but cease to exist before you use it.
Usually the best approach is to try to open the file, and handle the
error if the attempt fails. Providing information about *why* it
failed can be useful, but it isn't absolutely necessary, and it can't
be done portably.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: File exist
- From: Kenneth Brody
- Re: File exist
- References:
- File exist
- From: paytam
- Re: File exist
- From: ed
- Re: File exist
- From: Keith Thompson
- Re: File exist
- From: Claude Yih
- Re: File exist
- From: Flash Gordon
- Re: File exist
- From: Mr John FO Evans
- File exist
- Prev by Date: send tcp raw socket (bogus tcp header length)
- Next by Date: Re: send tcp raw socket (bogus tcp header length)
- Previous by thread: Re: File exist
- Next by thread: Re: File exist
- Index(es):
Relevant Pages
|