🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10384

Re: FileExists() is using wildcards

#10384
From: Ed Mulroy [TeamB]
Date: Mon, 26 Apr 2004 20:41
91 lines
3042 bytes
You might use one of these.

I like the second version because I to independently check for a file
or for a directory.

  -------------
  #include <io.h>

  bool MyFileExists(const char *name)
    {
    return !access(name, 0);
    }
  -------------

  -------------
  #include <windows.h>

  bool MyFileExists(const char *fname)
    {
    DWORD a = GetFileAttributes(name);

    return (a != INVALID_FILE_ATTRIBUTES) &&
             !(a & FILE_ATTRIBUTE_DIRECTORY);
    }

  bool MyDirExists(const char *fname)
    {
    DWORD a = GetFileAttributes(name);

    return (a != INVALID_FILE_ATTRIBUTES) &&
             (a & FILE_ATTRIBUTE_DIRECTORY);
    }
  -------------

.  Ed

> Hans Galema wrote in message
> news:408d6cad$1@newsgroups.borland.com...
>
> Had some bad hours searching for unexpected
> behaviour on a remote server.
>
> Finally I could track it down on a 'failing' of FileExists().
>
> There was a '?' in a FileName that was generated by code.
> The '?' was interpreted as a wildcard.
>
> Before loading the file in a TRichEdit I checked
> it precence by using FileExist.
>
> There came no answer from the server as the folowing
> LoadFromFile threw an exeption.
>
> Demo:
>
> void __fastcall TForm1::Button2Click(TObject *Sender)
> {
>    AnsiString FileName = "Unit1.?";
>
>    if ( FileExists ( FileName ) ) // This will find Unit1.cpp or
Unit1.h
>       {
>       ShowMessage ( FileName + "\n\nFileExists" );
>
>       Memo1->Lines->LoadFromFile ( FileName );   // exeption!
>       }
>    else
>       ShowMessage ( FileName + "\n\nno FileExists" );
> }
>
> There is nothing in the help for bcb3 that informs of FileExists
using
> wildcards.
>
> Now I can write my own file_exists() which does what I want:
>
> #include <stdio.h>
> bool file_exists ( char *path )
>          {
>          FILE *stream = fopen ( path, "rb" );
>
>          if ( ! stream ) return false;
>
>          fclose ( stream );
>
>          return true;
>          }
>
> But is there a more native solution ?
>
> Hans.
Technical Details
Message-ID: <408d73fa$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <408d6cad$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,8374fb71f8a662f4
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-04-26 14:10:16 PST
From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <408d6cad$1@newsgroups.borland.com>
Subject: Re: FileExists() is using wildcards
Date: Mon, 26 Apr 2004 16:41:21 -0400
Lines: 93
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 24.74.175.102
Message-ID: <408d73fa$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1083012090 24.74.175.102 (26 Apr 2004 13:41:30 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail