delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/26/07:02:08

From: Martijn Klingens <klingens AT dutccis DOT ct DOT tudelft DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Checking to see if I file exists
Date: Thu, 23 Oct 1997 21:44:24 +0100
Organization: Delft University of Technology
Lines: 14
Message-ID: <344FB728.E5E56BB@dutccis.ct.tudelft.nl>
References: <Pine DOT SUN DOT 3 DOT 95 DOT 971020141415 DOT 22091B-100000 AT lurch-fddi>
Reply-To: spaze AT dds DOT nl
NNTP-Posting-Host: ct111n191.ct.tudelft.nl
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

H. Anthony Hoyt wrote:
> 
>      I can't seem to remember how to check to see if I file exists or not.
> What I want is, if the user enters in a file name, to check to see if the
> file exists.  If so, I want to open the file, not overwrite it, read from
> the file then recreate the file before I finaly save the file.  (All in
> binary)  Any advice would be welcome.  Thanks

The most commonly used method is just to try opening the file. If fopen
returns NULL, there was an error, so you can assume the file doesn't
exist. You can ofcourse check what exactly went wrong, but in many cases
assuming a file doesn't exist if fopen () returns NULL is pretty safe.

Martijn Klingens

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019