🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: FileExists() is using wildcards

#10389
From: Hans Galema
Date: Tue, 27 Apr 2004 07:42
40 lines
2121 bytes
Ed Mulroy [TeamB] wrote:
> You might use one of these.

>     return !access(name, 0);

Interesting function. So DOS had it all already!

>   bool MyFileExists(const char *fname)
>     {
>     DWORD a = GetFileAttributes(name);
> 
>     return (a != INVALID_FILE_ATTRIBUTES) &&
>              !(a & FILE_ATTRIBUTE_DIRECTORY);
>     }

That did not compile for several reasons. The worst was that the
compiler (bcb3) could not know about INVALID_FILE_ATTRIBUTES.

I changed the code to:

   bool MyFileExists2(const char *fname)
     {
     DWORD a = GetFileAttributes(fname);  // winbase.h

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

      return (a != FILE_ATTRIBUTE_NORMAL) // 0x00000080 mapiwin.h winnt.h
              &&
            !(a & FILE_ATTRIBUTE_DIRECTORY);// 0x00000010 mapiwin.h winnt.h
     }

Now it does compile. And it works.

You just typed that I suppose. What would be the right value
for INVALID_FILE_ATTRIBUTES ?

Thanks for the reply.

Hans.
Technical Details
Message-ID: <408e0d39$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsrout1.ntli.net!news-in.ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <408d6cad$1@newsgroups.borland.com> <408d73fa$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-27 00:39:25 PST
Date: Tue, 27 Apr 2004 09:42:14 +0200
From: Hans Galema <dontusethis@dontusethis.nl>
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.6b) Gecko/20031208
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: FileExists() is using wildcards
References: <408d6cad$1@newsgroups.borland.com> <408d73fa$1@newsgroups.borland.com>
In-Reply-To: <408d73fa$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 129.125.202.241
Message-ID: <408e0d39$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1083051321 129.125.202.241 (27 Apr 2004 00:35:21 -0700)
Lines: 40
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsrout1.ntli.net!news-in.ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail