Solved

Count directories?

Posted on 2000-03-17
7
255 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
  • 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 50 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
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.

 
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

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

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 97
LAN or WAN ? 11 90
tidtcpserver connection lost handle 2 83
Tvertscrollbox like a whatsapp layout 5 26
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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