🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to conclude a file or directory exists

#16553
From: Greg Brewer
Date: Tue, 06 May 2003 23:21
59 lines
2832 bytes
There are possible problems with this answer.

First, you need to test the string for the presence of * or ?.  If either of
those characters exist then you may get what amounts to a false positive.

Also, watch out for filenames such as nul, prn, con, etc.

Second, you may have problems with network drives.  I have had problems with
them and I never found a satisfactory solution.  On the network I was
working on, a particular test would work; however, I would get false
positives on my customer's network.  Some networks identified a file as
existing when it didn't.  Some identified a folder as a file.  It was messy.

I'm afraid I do not remember the particulars of what I had trouble with and
what I did to fix it.

Greg
"Nick B. Cassos" <nbc@no_spam.ath.forthnet.gr> wrote in message
news:encfbvo8rr3i96t9llc1mbo2917lb8vhda@4ax.com...
> On Tue, 6 May 2003 19:52:54 +0800, "Sky" <akeehuang@163.net> wrote:
>
> >hi all,
> >I want to know whether a file or directory is existed or not?
> >not use VCL, I know the FileExists/DirectoryExists in VCL.
>
> bool __fastcall MyDirExists(const AnsiString ADir)
> {
>     bool  Result = false;
>     DWORD AAttr  = ::GetFileAttributes(ADir.c_str());
>
>     if (AAttr != 0xFFFFFFFF)
>     {
>         if ((AAttr & FILE_ATTRIBUTE_DIRECTORY) != 0)
>         Result = true;
>     }
>
>     return Result;
> }
>
> bool __fastcall MyFileExists(const AnsiString AFile)
> {
>     bool            Result = false;
>     WIN32_FIND_DATA FD;
>     HANDLE          Handle = FindFirstFile(AFile.c_str(),&FD);
>
>     if (Handle != INVALID_HANDLE_VALUE)
>     {
>         ::FindClose(Handle);
>
>         if ((FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
>         Result = true;
>     }
>
>     return Result;
> }
>
> --
>
> Nick B. Cassos
Technical Details
Message-ID: <3eb84472$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3eb7a237@newsgroups.borland.com> <encfbvo8rr3i96t9llc1mbo2917lb8vhda@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,753d602e8f21d00d
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-05-06 16:33:34 PST
From: "Greg Brewer" <Greg@Brewer.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3eb7a237@newsgroups.borland.com> <encfbvo8rr3i96t9llc1mbo2917lb8vhda@4ax.com>
Subject: Re: How to conclude a file or directory exists
Date: Tue, 6 May 2003 18:21:08 -0500
Lines: 61
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 206.180.153.52
Message-ID: <3eb84472$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1052263538 206.180.153.52 (6 May 2003 16:25:38 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail