开发者

Finding folders

开发者 https://www.devze.com 2022-12-23 07:43 出处:网络
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???

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.

Recursive Search example at DelphiTricks.com


http://www.delphibasics.co.uk/RTL.asp?Name=FindFirst


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; 


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

0

精彩评论

暂无评论...
验证码 换一张
取 消