Hello. I want to find how much folders are in folder or I should say how much SubFolreds are in folder. So, how I should do that???
P.S. I'm programing with Delphi
Hello. I want to find how much folders are in folder or I should say how much SubFolreds are in folder. So, how I should do that???
P.S. I'm programing with Delphi
In addition to the FindFirst trick, you'll need to use recursion, if you want to count all folders in the tree (i.e. all levels) and not just the immediate folder.
Here is a short example of the recursive approach, looks to be exactly what you're looking for. Hint: the Find() method is used recursively.
You didn't mention which version of Delphi you use. The latest version has the IOUtils unit which includes the TDirectory class. See an example here: link text
It depends on your compiler version. If you are using Delphi 2010, the simplest code I can come up with is this:
uses IOUtils, Types;
function GetSubDirCount(const Path: string): Cardinal;
var
StrArray : TStringDynArray;
begin
StrArray := TDirectory.GetDirectories(Path,'*',IOUtils.TSearchOption.soAllDirectories);
Result := Length(StrArray);
end;