🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to conclude a file or directory exists

#16543
From: Nick B. Cassos
Date: Tue, 06 May 2003 13:07
40 lines
1882 bytes
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: <encfbvo8rr3i96t9llc1mbo2917lb8vhda@4ax.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!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3eb7a237@newsgroups.borland.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 06:15:07 PST
From: Nick B. Cassos <nbc@no_spam.ath.forthnet.gr>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to conclude a file or directory exists
Date: Tue, 06 May 2003 16:07:35 +0300
Message-ID: <encfbvo8rr3i96t9llc1mbo2917lb8vhda@4ax.com>
References: <3eb7a237@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 213.16.151.30
X-Trace: newsgroups.borland.com 1052226450 213.16.151.30 (6 May 2003 06:07:30 -0700)
Lines: 40
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!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail