Solved

FindFirst to return Dir's only???

Posted on 1998-07-28
9
463 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:LostOne
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Oh, well ....my way won't work then..

Regards,
Viktor Ivanov
0
 

Author Comment

by:LostOne
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now