Solved

FindFirst to return Dir's only???

Posted on 1998-07-28
9
471 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 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