Solved

Count directories?

Posted on 2000-03-17
7
259 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 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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