Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why doesn't FindFirst only find directories?

1,026 views
Skip to first unread message

Ikke

unread,
Jul 23, 2009, 1:28:31 PM7/23/09
to
Hi everybody,

Another problem has just popped up today - I have the following piece of
code in my project:

if FindFirst(directory + '*.*', faDirectory, search) = 0 then

At first I assumed that this would only return directories, instead of
files and directories when using faAnyFile. After testing, however, it
turned out that the FindFirst operation returns files as well!

When I use faAnyFile - faDirectory, only files are returned, so I really
don't understand why files are being returned as well as directories in my
first example.

Could somebody please explain this to me?

Thanks!

Ikke

alang...@aol.com

unread,
Jul 23, 2009, 2:16:53 PM7/23/09
to

Look up FindFirst in Delphi Help. Part of the text says . . .

"The Attr parameter specifies the special files to include in addition
to all normal files."

Note the "in addition to all normal files".

You have to get all files plus directories. Then when FindFirst
returns check the value of the Attr element of TSearchRec (F) for
faDirectory. If it's there then you have a directory, if it's not then
FindNext & repeat.

if you meet a problem, the first thing to do is to read help & see if
you understand the matter <g>.

Alan Lloyd

Ikke

unread,
Jul 23, 2009, 2:49:07 PM7/23/09
to
"alang...@aol.com" <alang...@aol.com> wrote in
news:235c29bd-1160-4a1b...@g31g2000yqc.googlegroups.com:

<snip>


> Look up FindFirst in Delphi Help. Part of the text says . . .
>
> "The Attr parameter specifies the special files to include in addition
> to all normal files."
>
> Note the "in addition to all normal files".

Ah... I see - that would indeed explain it :)



> You have to get all files plus directories. Then when FindFirst
> returns check the value of the Attr element of TSearchRec (F) for
> faDirectory. If it's there then you have a directory, if it's not then
> FindNext & repeat.

I did that, I excluded all files after finding them with
findfirst/findnext. But since there are only a few directories to find,
but thousands of files, this operation takes quite long.

A better question would probably be: how do I get a list of all
directories and subdirectories, starting from a specified directory?

Is findfirst/findnext the only way?



> if you meet a problem, the first thing to do is to read help & see if
> you understand the matter <g>.

True - thanks though.

Ikke

BRoberts

unread,
Jul 23, 2009, 8:14:37 PM7/23/09
to
"Ikke" <ik...@hier.be> wrote in message
news:Xns9C51D3C7D8...@69.16.176.253...

> "alang...@aol.com" <alang...@aol.com> wrote in
> news:235c29bd-1160-4a1b...@g31g2000yqc.googlegroups.com:
>
> <snip>
>> Look up FindFirst in Delphi Help. Part of the text says . . .
>>
>> "The Attr parameter specifies the special files to include in addition
>> to all normal files."
>>
>> Note the "in addition to all normal files".
>
> Ah... I see - that would indeed explain it :)
>
>> You have to get all files plus directories. Then when FindFirst
>> returns check the value of the Attr element of TSearchRec (F) for
>> faDirectory. If it's there then you have a directory, if it's not then
>> FindNext & repeat.
>
> I did that, I excluded all files after finding them with
> findfirst/findnext. But since there are only a few directories to find,
> but thousands of files, this operation takes quite long.
>
> A better question would probably be: how do I get a list of all
> directories and subdirectories, starting from a specified directory?
>
> Is findfirst/findnext the only way?
>

Take a look at the Win32 FindFirstFileEx API, see in particular the
fSearchOp setting of FindExSearchLimitToDirectories.


Dr J R Stockton

unread,
Jul 24, 2009, 9:22:41 AM7/24/09
to
In comp.lang.pascal.delphi.misc message <Xns9C51C61DB9E81ikkehierbe@69.1
6.176.253>, Thu, 23 Jul 2009 17:28:31, Ikke <ik...@hier.be> posted:

It is because of what Microsoft thinks reasonable.

The solution is to search always for faAnyFile, or $FF, and then to test
the attributes of what you find.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
NOT <URL:http://support.codegear.com/newsgroups/>: news:borland.* Guidelines

0 new messages