Article View: borland.public.cppbuilder.nativeapi
Article #5003Re: directory list problems
From: Remy Lebeau (TeamB)
Date: Tue, 25 Oct 2005 17:47
Date: Tue, 25 Oct 2005 17:47
44 lines
2257 bytes
2257 bytes
"robert" <rob@no-spam.boo> wrote in message
news:435e6c76$1@newsgroups.borland.com...
> When I call the routing the first time it is perfect, but the
> others time I try to call the same routine It doesn't work:
> "GetLastError" is == ERROR_NO_MORE_FILES !
> Why that ?
Not every API operation resets GetLastError(). You should only be using
GetLastError() when an actual error occurs. In your case, the second time
you call your code, it is picking up the error from the first time the code
is called. You need to change your code to not use GetLastError() at all to
control the looping. Use the following code instead:
void __fastcall TForm1::ShowDir()
{
WIN32_FIND_DATA FileData = {NULL};
HANDLE hFind = FindFirstFile("c:\\*.*", &FileData);
if( hFind == INVALID_HANDLE_VALUE )
{
DWORD ErrorCode = GetLastError()
if( ErrorCode == ERROR_NO_MORE_FILES )
Memo->Lines->Add("No files found");
else
Memo->Lines->Add("Search failed : error " +
AnsiString(ErrorCode));
return;
}
do
{
// your code here...
}
while( FindNextFile(hFind, &FileData) );
FindClose(hFind);
}
Gambit
Technical Details
Message-ID:
<435e6f17$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<435e6c76$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fb06c70f9d4d1eee X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <435e6c76$1@newsgroups.borland.com> Subject: Re: directory list problems Date: Tue, 25 Oct 2005 10:47:34 -0700 Lines: 46 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: 68.69.17.41 Message-ID: <435e6f17$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1130262295 68.69.17.41 (25 Oct 2005 10:44:55 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail