Re: File exist



Mr John FO Evans wrote:
In article <76reh3xu85.ln2@xxxxxxxxxxxxxxxxxxxxxxx>, Flash Gordon
<spam@xxxxxxxxxxxxxxxxxx> wrote:
Claude Yih wrote:
Keith Thompson wrote:

ed <ed@xxxxxxxxxxx> writes:
On 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.
I learnt from others that there is a function named access can be used
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.
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'?

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
.



Relevant Pages

  • Re: Need help on modifying and assembly of a small program!
    ... care for "international support" at the moment...BUT will you care _LATER_? ... make your keyboard driver use "keymaps" or something (which simply ... that there's a kind of "standard" for typing English with their Cyrillic ... This is the "portability" of the OS source ...
    (alt.lang.asm)
  • Re: removing a loop cause it to go at half the speed?
    ... The concepts are also useful because they are well defined by the same standard that defined the C language. ... If the standard says it is undefined behaviour then even if your implementation defines it you know that you will have to check whether it is documented for *every* system you want to use it on in the future, and you may well come across a system which leaves it completely undefined and possibly even causes random behaviour. ... or you will have on some other platform. ... Portability is not always easy or possible, but the starting point is knowing what the C standard guarantees and what it doesn't. ...
    (comp.lang.c)
  • Re: <ctype.h> toLower()
    ... See the C Standard. ... >> tolower() is implemented. ... >> platform, without even having to know which character set is used on that ... is, however, an error in portability for me to *call* that macro. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Storgae durations
    ... standard you referred to is no longer current. ... advocating C99 and saying that C90 is obsolete, ... Then you are in no position to make an argument about C99's portability ... there are implementations for C99 that target those platforms. ...
    (comp.lang.c)
  • Re: pascal equivalent of python "sleep"
    ... portability problems which exist in Pascal are simply ... Pascal has a standard, the ISO 7185 standard. ... the Borland series implementations. ... What areas should be covered by standard libraries? ...
    (comp.lang.pascal.misc)