Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FindFirst to return Dir's only???

Posted on 1998-07-28
9
Medium Priority
?
481 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

721 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