Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Count directories?

Posted on 2000-03-17
7
Medium Priority
?
264 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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