is using
if(open("file",O_EXCL) != -1){ printf("File does
exists")}else{printf("file does not exists"); }
a good way of checking if a file exists or not, if not how should I do it ? 15 114122
a standard C compatible way could be:
FILE *fp = fopen("file","r");
if( fp ) {
// exists
fclose(fp);
} else {
// doesnt exist
}
Geiregat Jonas wrote: is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); }
a good way of checking if a file exists or not, if not how should I do it ?
Robert Frunzke <Ro**************@freenet.de> scribbled the following: a standard C compatible way could be:
FILE *fp = fopen("file","r"); if( fp ) { // exists fclose(fp); } else { // doesnt exist
Doesn't exist, exists but isn't readable, exists but already has too
many locks, or other similar reasons.
}
It's impossible to check existence for certain in pure ISO standard C.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg
Geiregat Jonas <en***@sdf-eu.org> wrote: is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); }
a good way of checking if a file exists or not, if not how should I do it ?
I would recommend using 'fopen' instead to use a standard c function.
However, standard C doesn't provide any guaranteed way to determine
whether a file exists or not. fopen can fail even if a file does exist.
However, it is possible that it is a reasonable method for your system,
but that question could only be answered by people knowledgeable with
your specific system.
--
== Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===
Joona I Palaste wrote: Robert Frunzke <Ro**************@freenet.de> scribbled the following:
a standard C compatible way could be:
FILE *fp = fopen("file","r"); if( fp ) { // exists fclose(fp); } else { // doesnt exist
Doesn't exist, exists but isn't readable, exists but already has too many locks, or other similar reasons.
}
It's impossible to check existence for certain in pure ISO standard C.
Using the stat function would solve some probleme's because you don't
need any access rights. I think stat is the best way (I'm using linux).
Op Wed, 07 Jan 2004 22:35:17 +0000 schreef Geiregat Jonas
<en***@sdf-eu.org>: Joona I Palaste wrote: Robert Frunzke <Ro**************@freenet.de> scribbled the following:
a standard C compatible way could be:
FILE *fp = fopen("file","r"); if( fp ) { // exists fclose(fp); } else { // doesnt exist
Doesn't exist, exists but isn't readable, exists but already has too many locks, or other similar reasons.
}
It's impossible to check existence for certain in pure ISO standard C. Using the stat function would solve some probleme's because you don't need any access rights. I think stat is the best way (I'm using linux).
access rights and stat are unknown to pure ISO standard C.
--
Coos
Geiregat Jonas <en***@sdf-eu.org> writes: is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); }
a good way of checking if a file exists or not, if not how should I do it ?
There's no really good portable way to determine whether a named file
exists; you'll probably have to resort to system-specific methods
(which you can ask about in another newsgroup).
Before you do, you should define more clearly what information you're
looking for and what you intend to do with it. On a multi-processing
system, for example, if your logic is something like this:
if (file exists) {
open existing file
}
else {
create new file
initialize new file
}
you should allow for the possibility that the file is created <OT>by
another process</OT> after you check for its existence and before you
attempt to create it.
Note also that if a file doesn't exist, that doesn't imply that you
have permission to create it.
In many cases, it may not be possible to determine whether a file
exists. On a system with user accounts and directories with
permission settings, an attempt to determine whether a file exists may
fail because you don't have permission to read the directory that may
or may not contain it.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Geiregat Jonas <en***@sdf-eu.org> wrote in message news:<3f**********************@news.skynet.be>... is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); }
a good way of checking if a file exists or not, if not how should I do it ?
In my opinion, the best option is to use access() call instead of
open() call. In this case, the above given code will look like:
if (access("file", F_OK) == 0)
{
printf("Files does exists");
}
else
{
printf("File does not exist");
...
}
Regards,
- Rahul Agarkar
Rahul Agarkar <ra***********@hotmail.com> scribbled the following: Geiregat Jonas <en***@sdf-eu.org> wrote in message news:<3f**********************@news.skynet.be>... is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); }
a good way of checking if a file exists or not, if not how should I do it ?
In my opinion, the best option is to use access() call instead of open() call. In this case, the above given code will look like:
if (access("file", F_OK) == 0) { printf("Files does exists"); } else { printf("File does not exist"); ... }
Neither access() or open() are ISO standard C functions. Whatever next,
will you be suggesting OpenFile() in <windows.h> or something?
(That function name might be wrong. I haven't actually *looked* at
<windows.h>.)
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"This isn't right. This isn't even wrong."
- Wolfgang Pauli
Rahul Agarkar wrote: Geiregat Jonas <en***@sdf-eu.org> wrote in message
is using if(open("file",O_EXCL) != -1) printf("File does exists"); else printf("file does not exists");
a good way of checking if a file exists or not, if not how should I do it ?
In my opinion, the best option is to use access() call instead of open() call. In this case, the above given code will look like:
if (access("file", F_OK) == 0) printf("Files does exists"); else { printf("File does not exist"); ... }
(slightly reformatted). open, access, O_EXCL and F_OK do not
exist in standard C, the subject of this newsgroup. Please do not
give off-topic answers here, where there may well be nobody to
correct any errors.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
CBFalconer wrote: Rahul Agarkar wrote:
Geiregat Jonas <en***@sdf-eu.org> wrote in message
is using if(open("file",O_EXCL) != -1) printf("File does exists"); else printf("file does not exists");
a good way of checking if a file exists or not, if not how should I do it ?
In my opinion, the best option is to use access() call instead of open() call. In this case, the above given code will look like:
if (access("file", F_OK) == 0) printf("Files does exists"); else { printf("File does not exist"); ... }
(slightly reformatted). open, access, O_EXCL and F_OK do not exist in standard C, the subject of this newsgroup. Please do not give off-topic answers here, where there may well be nobody to correct any errors.
Where could I find information what is Standard ISO C
and information about other standards ?
I'm using stat now.
Geiregat Jonas wrote: CBFalconer wrote: Rahul Agarkar wrote:
Geiregat Jonas <en***@sdf-eu.org> wrote in message
is using if(open("file",O_EXCL) != -1) printf("File does exists"); else printf("file does not exists");
a good way of checking if a file exists or not, if not how should I do it ?
In my opinion, the best option is to use access() call instead of open() call. In this case, the above given code will look like:
if (access("file", F_OK) == 0) printf("Files does exists"); else { printf("File does not exist"); ... }
(slightly reformatted). open, access, O_EXCL and F_OK do not exist in standard C, the subject of this newsgroup. Please do not give off-topic answers here, where there may well be nobody to correct any errors.
Where could I find information what is Standard ISO C and information about other standards ? I'm using stat now.
Try:
<http://www.dinkumware.com>
<http://std.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/>
for the latter I advise downloading the text version for easy
searching, grepping, etc.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Geiregat Jonas wrote: Where could I find information what is Standard ISO C and information about other standards ? I'm using stat now.
The obvious answer is, the ISO C Standard.
Brian Rodenborn
Default User wrote: Geiregat Jonas wrote:
Where could I find information what is Standard ISO C and information about other standards ? I'm using stat now.
The obvious answer is, the ISO C Standard.
Brian Rodenborn
I think it was obvious that I knew that but was looking for the official
place to get it from.
Geiregat Jonas <en***@sdf-eu.org> wrote: I think it was obvious that I knew that but was looking for the official place to get it from.
I believe this is it:
Search for:
9899:1999
at http://www.iso.ch
which should bring up this page: http://tinyurl.com/3bpmj
which is what I believe you are looking for.
--
== Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===
Eric wrote: Geiregat Jonas <en***@sdf-eu.org> wrote:
I think it was obvious that I knew that but was looking for the official place to get it from.
I believe this is it:
Search for:
9899:1999
at
http://www.iso.ch
which should bring up this page:
http://tinyurl.com/3bpmj
which is what I believe you are looking for.
It should also be available from various national standards bodies, such
as ANSI in the US (which sells the downloadable PDF for $18, last I heard).
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alex Chan |
last post by:
Hi Group,
I encountered something strange with File.Exists(string path). This
function is simply to check whether a file exists in certain path. However,
if the path starts with "file:\" in the...
|
by: Bas |
last post by:
I'm using
If File.Exists("c:\docs\myfile.txt")
msgbox("Found")
End
This work fine on machine with Vb.Net installed but NOT on regular
workstations ie. when deployed!!
Any ideas?
|
by: Ricardo Luceac |
last post by:
Hi all.
I'm having a problem with this, I have look if a file exists, if don't wait
till it is created and if it exists I need to open it. I do the following:
for (; ; )
{
|
by: PiotrKolodziej |
last post by:
Hi
I want to check if the file can be executed. Its directory path is either in
environment 'path' variable or isn't there.
Exists method seems like it's not checking variables at all.
For any...
|
by: =?Utf-8?B?R29yZG9u?= |
last post by:
Hi;
What is the correct syntax for checking for a file's existence based on it's
extension ?
Example:
Imports system.io
Dim path as string = "C:\myDirectory\*.txt"
|
by: Army1987 |
last post by:
Is this a good way to check wheter a file already exists?
#include <stdio.h>
#include <stdlib.h>
int ask(const char *prompt);
typedef char filename;
int main(int argc, char *argv)
{
FILE...
|
by: darkslide |
last post by:
Hi,
I'm checking if a file exists with the following code;
If System.IO.File.Exists("C:\test.txt") = True Then
MsgBox("File Exists")
Else
MsgBox("File Does Not Exist")
End If
...
|
by: sprash |
last post by:
Newbie question:
I'm trying to determine if a file physically exists regardless of the
permissions on it
Using File.Exists() returns false if it physically exists but the
process does not...
|
by: timexsinclair2068 |
last post by:
This is a very simple question. Is there a simple,short way of
checking if the application's App.Config file exists?
Thanks!
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |