🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: FileExists() is using wildcards

#10388
From: Hans Galema
Date: Tue, 27 Apr 2004 07:43
46 lines
2675 bytes
Remy Lebeau (TeamB) wrote:

> "?" is an invalid character for filenames.

Yes, indeed. And it can be used as a wildcard.

>>   AnsiString FileName = "Unit1.?";
>>
>>   if ( FileExists ( FileName ) ) // This will find Unit1.cpp or Unit1.h
> 
> You can't do wildcard matching like that.  FileExists() does not support
> wildcards at all. 

Well if you read my post again then you will see that I reported that
FileExist DOES support wildcards. And that amazes me. The help does
not state it. FileExists would even find Unit1.cpp for FileName == "*nit.?".

 > If you need that, then use FindFirst() instead:

No I do not need wildcard matching. I need a file exist function
that reports if a file for a filename exists. The '?' in my
filename was unintentionally, caused by the fact that the filename was
generated by code. The intention of using FileExist was to get a false
for unvalid filenames. To my surprise FileExist does not care for unvalid
filenames, but allows wildcards in them.

>     TSearchRec sr;
>     if( FindFirst("drive:\\path\\" + FileName, faAnyFile & ~faDirectory, sr)
> == 0 )
>     {
>         // sr contains the first fileame that matched the wildcard mask.

Until now, my experience was that FindFirst/FindNext could NOT be used
with wildcards. I never succeeded to write code for that. But I will try
your suggestion.

>>      Memo1->Lines->LoadFromFile ( FileName );   // exeption!
> 
> You can't load a filename with wildcards in it.  You need to specify the
> EXACT file to load.

Yes of course. That was what I showed.

Thanks for the reply.

Hans.
Technical Details
Message-ID: <408e0d6a$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> <408d8056$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:43:03 +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> <408d8056$1@newsgroups.borland.com>
In-Reply-To: <408d8056$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: <408e0d6a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1083051370 129.125.202.241 (27 Apr 2004 00:36:10 -0700)
Lines: 46
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