Re: File exist
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 19:26:16 +0100
Mr John FO Evans wrote:
In article <76reh3xu85.ln2@xxxxxxxxxxxxxxxxxxxxxxx>, Flash Gordon
<spam@xxxxxxxxxxxxxxxxxx> wrote:
Claude Yih wrote:Keith Thompson 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.
ed <ed@xxxxxxxxxxx> writes:I learnt from others that there is a function named access can be usedOn 16 Apr 2006 01:53:03 -0700[...]
paytam@xxxxxxxxx wrote:
Can anyone tell me how can I check that a file exist or no.Try using stat(5).There is no stat() function in standard C. Using it will limit the
portability of your code. See comp.unix.programmer.
to detect if a dedicated file exists. The function is as follows:
int access (char* filename, int mode)
For instance, if I wanted to know whether /opt/test.log exists, I would
call this function as
int flag = access("/opt/test.log", 0);
However, this function is included in <io.h>, perhaps it's not a
standard function either.
What is wrong with attempting to open the file and if there is no error
closing it again? Surely this is standard 'C'?
It's standard C but it does not prove the file does not exist. It might exist but your have permission set preventing you from opening it (perhaps a different user owns it) or another process might have it opened exclusively, or...
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
.
- Follow-Ups:
- Re: File exist
- From: Mr John FO Evans
- 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: Re: char* pname = "Harry"
- Next by Date: Re: First C Program, Problems getting serial data
- Previous by thread: Re: File exist
- Next by thread: Re: File exist
- Index(es):
Relevant Pages
|