Solved

FindFirst to return Dir's only???

Posted on 1998-07-28
9
468 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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