?
Solved

Count directories?

Posted on 2000-03-17
7
Medium Priority
?
261 Views
Last Modified: 2010-04-04
Lets say i have 10 files in pic directory and i have 3 subdirs. How i can count, how many subdirs i have in pic directory?.

mhieta
0
Comment
Question by:mhieta
[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
7 Comments
 
LVL 2

Expert Comment

by:rene100
ID: 2629529
Hi...

var
Found: Integer;
SearchRec: TSearchRec;
DirCount: Integer;
begin
DirCount:=0;
Found := FindFirst('c:\pic\*.*', faAnyFile or faDirectory, SearchRec);
    while Found = 0 do
    begin
      if searchRec.Attr=faDirectory then
         Inc(DirCount);
      Found := FindNext(SearchRec);
    end;
    FindClose(SearchRec);
showmessage('Found '+IntToStr(DirCount));
end;

Perhaps you habe to decrease DirCount by 2, because there are always the 2 standard dirs . and ..

regards
rene
0
 

Accepted Solution

by:
netbeto earned 200 total points
ID: 2629668
Hy mhieta,
I've done a test to try a way to answer you and found a "solution" if you like that pleace give me the points!!!!

procedure TForm1.Button1Click(Sender: TObject);
var SearchRec: TSearchRec;
    fDirPath: String;
    count: Integer;
begin
 fDirPath := Edit1.Text + '\*.*';
 count := 0;
 try
  if FindFirst(fDirPath, faAnyFile, SearchRec) = 0 then
   begin
    while (FindNext(SearchRec) = 0) do
     begin
      if (SearchRec.Attr = faDirectory) and (SearchRec.Name <> '..') then
        Inc(Count);
     end;
   end;
  Label1.Caption := IntToStr(Count);
  FindClose(SearchRec);
 except
  FindClose(SearchRec);
 end;
end;

Anyway, I hope you like....

Beto.
0
 
LVL 2

Expert Comment

by:rene100
ID: 2630160
to netbeto

why do you suggest almost excatly the same solution as i did and claim for the points??

rene
0
Technology Partners: 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!

 
LVL 2

Author Comment

by:mhieta
ID: 2635577
netbeto, your code works perfectly and also rene's code works fine. But netbeto's code is more flexible for many situations in future. I asked: "How i can count, how many subdirs i have in pic directory?." so rene is also right. So i give both of you...points of this question.

mhieta
0
 
LVL 2

Author Comment

by:mhieta
ID: 2635581
Many thanks for the code!

mhieta
0
 

Expert Comment

by:netbeto
ID: 2635822
to rene
I did, because when I suggested your comment wasn't there (I was making the answer while connected, my is because that I didn't see your's suggest) then I asked for the points, but doesn't matter I just want to give a solution to my "Expertsn Friends".

Netbeto.
0
 
LVL 2

Expert Comment

by:rene100
ID: 2635949
ok netbeto, didn't want to offend you..;-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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