473,889 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Good way of checking if file exists ?

is using
if(open("file", O_EXCL) != -1){ printf("File does
exists")}else{p rintf("file does not exists"); }

a good way of checking if a file exists or not, if not how should I do it ?

Nov 14 '05
15 114221
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.

Nov 14 '05 #11
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********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #12
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
Nov 14 '05 #13
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.

Nov 14 '05 #14
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... ===
Nov 14 '05 #15
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.
Nov 14 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6029
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 begining of the string, no matter the file exists or not. it will return false without any exception. It is expected? Regards, Alex
6
4245
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?
10
14426
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 (; ; ) {
2
538
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 help thanks.
2
1321
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"
26
4976
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 *in, *out;
13
24237
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 For some reason it always returns false even though the file does exist. Any suggestions? Could this be a security issue?
7
19150
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 have the necessary permissions. One hack could be to check for length and that would throw a FileNotFoundException ...but there is got to be a better way!
1
3245
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!
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9807
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10789
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7150
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5828
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4647
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.