查找文件夹

发布于 2024-08-25 14:00:17 字数 84 浏览 2 评论 0原文

我想知道文件夹中有多少文件夹,或者我应该知道文件夹中有多少 SubFolred。那么,我应该怎么做呢???

PS我正在用Delphi编程

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

静谧 2024-09-01 14:00:17

除了 FindFirst 技巧之外,如果您想计算树中的所有文件夹(即所有级别)而不仅仅是直接文件夹,您还需要使用递归。

这是递归方法的一个简短示例,看起来正是您正在寻找的。提示:Find() 方法是递归使用的。

DelphiTricks.com 上的递归搜索示例

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

夜访吸血鬼 2024-09-01 14:00:17

这取决于您的编译器版本。如果您使用的是 Delphi 2010,我能想到的最简单的代码是这样的:

uses IOUtils, Types;

function GetSubDirCount(const Path: string): Cardinal;
var
  StrArray : TStringDynArray;
begin
  StrArray := TDirectory.GetDirectories(Path,'*',IOUtils.TSearchOption.soAllDirectories);
  Result := Length(StrArray);
end; 

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; 
挥剑断情 2024-09-01 14:00:17

你没有提到你使用的是哪个版本的Delphi。最新版本有 IOUtils 单元,其中包括 TDirectory 类。请参阅此处的示例:链接文本

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文