Solved

FindFirst to return Dir's only???

Posted on 1998-07-28
9
476 Views
Last Modified: 2010-04-04
I've been trying to figure out how to get delphi 3.0 to return only the subdirectories of a particular path. I've tried using findfirst with faDirectory but it still returns files and not just dir's. How can I get a list of only dir's?

Thanks
0
Comment
Question by:LostOne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 1

Expert Comment

by:andrey070798
ID: 1358912
Hi, LostOne!

There is way to get list of directories by using FindFirst/FindNext functions only if you go thru all of the files and check Attr param for bit 0x0000010 (faDirectory).

That what I've got in Delphi help for Attr parameter:
 >The Attr parameter specifies the special files to include in ADDITION to all normal files.

If you need more information how to do that, I can write example.
ask mne in a comment.
Andrey
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1358913
Why don't you use the DirectoryComboBox to be invisible, and then work your way with it... I think it will work. Of course it depends on what are you trying to do :)

Regards,
Viktor Ivanov
0
 

Author Comment

by:LostOne
ID: 1358914
andrey: Ya I looked at the Attr param and figured it would prob do what I wanted. I was just hoping for a more direct solution(faster). Unless I can come up with something better I think Attr will be the way to go.

viktornet: Not sure if an invisible DirectoryComboBox would work... I'll take a closer look at it. What I'm trying to do is create a recursive dir search. For example I want to be able to search c:\ and all of it's sub directories(all levels) for a particular file pattern(*.zip). Searching for the files is easy, I'm just having a hard time finding an easy way to get the sub directories of a dir.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LostOne
ID: 1358915
andrey: Ya I looked at the Attr param and figured it would prob do what I wanted. I was just hoping for a more direct solution(faster). Unless I can come up with something better I think Attr will be the way to go.

viktornet: Not sure if an invisible DirectoryComboBox would work... I'll take a closer look at it. What I'm trying to do is create a recursive dir search. For example I want to be able to search c:\ and all of it's sub directories(all levels) for a particular file pattern(*.zip). Searching for the files is easy, I'm just having a hard time finding an easy way to get the sub directories of a dir.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1358916
Oh, well ....my way won't work then..

Regards,
Viktor Ivanov
0
 

Author Comment

by:LostOne
ID: 1358917
Ok thanks anyway viktor =) andrey, feel free to answer the question so I can give you your credit.

0
 
LVL 2

Expert Comment

by:freter
ID: 1358918
Hi LostOne,
the answer given by andrey is absolutely correct. It is one of Microsoft secrets why FindFirst / Next opertae in the described way. Anyway, the described method of double-checking is quite fast, isn't it?
One other possibility to get subdirs is to use the sehll enumerators for the shell name space, but i guess, that's bit oversized. Nevertheless, you can get loads of good examples of how to use the enumerators on the Delphi Superage.

Cheers,
Freter
0
 
LVL 5

Accepted Solution

by:
inter earned 100 total points
ID: 1358919
Hi there this is what I have:

// This one returns all the subdirs of a directory named Path
// and fill the FileList with full path to those dirs
// NOTE : You should not add '\' to the end of the Path.
//        So if you want to search on c just write 'c:'
function FindFileEx(Path : String;FileList:TStrings):boolean;
var
  SearchRec : TSearchRec;
  res       : integer;
begin
    res := FindFirst(Path+'\*.*', faDirectory, SearchRec);
    while res = 0 do
    begin
      if (SearchRec.Name = '.') or (SearchRec.Name = '..') then
      begin
        res := FindNext(SearchRec);
        continue;
      end;
      if SearchRec.Attr and faDirectory > 0 then
         FileList.Add(Path+'\'+SearchRec.Name);
      res := FindNext(SearchRec);
      Application.ProcessMessages;
    end;
end;

Bye,
Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1358920
Hi,
Excuse me, I just jumped in. So you may reject the answer, I have already answer such a question which is to search for a file recursively in a given path so i just modify and post.
Have a nice day,
Igor
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question