Solved

Count directories?

Posted on 2000-03-17
7
252 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

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

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

757 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

18 Experts available now in Live!

Get 1:1 Help Now