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
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
<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
Take a look at the Win32 FindFirstFileEx API, see in particular the
fSearchOp setting of FindExSearchLimitToDirectories.
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