首页 > 其他分享 >Delphi 2010 新增功能之: IOUtils 单元(4): TDirectory.GetDirectories

Delphi 2010 新增功能之: IOUtils 单元(4): TDirectory.GetDirectories

时间:2023-08-11 20:23:32浏览次数:33  
标签:Delphi GetDirectories dfs TObject IOUtils procedure str TDirectory Memo1

转自万一  https://www.cnblogs.com/del/archive/2009/10/16/1584768.html

 

和 TDirectory.GetFiles 用法一样, TDirectory.GetDirectories 是用来获取子目录的.

另外还有 TDirectory.GetFileSystemEntries 可同时获取文件与子目录, 用法都一样.



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses IOUtils, Types;

const path = 'C:\Program Files\Embarcadero\RAD Studio\7.0';

//获取指定目录下的文件与子目录
procedure TForm1.Button1Click(Sender: TObject);
var
  dfs: TStringDynArray;
  str: string;
begin
  dfs := TDirectory.GetFileSystemEntries(path);
  Memo1.Clear;
  for str in dfs do Memo1.Lines.Add(str);
end;

//获取指定目录下的、名称是 L 开头的文件与子目录
procedure TForm1.Button2Click(Sender: TObject);
var
  dfs: TStringDynArray;
  str: string;
begin
  dfs := TDirectory.GetFileSystemEntries(path, 'L*');
  Memo1.Clear;
  for str in dfs do Memo1.Lines.Add(str);
end;

//获取指定目录及嵌套目录下的所有文件与子目录
procedure TForm1.Button3Click(Sender: TObject);
var
  dfs: TStringDynArray;
  str: string;
begin
  dfs := TDirectory.GetFileSystemEntries(path + '\source', TSearchOption.soAllDirectories, nil);
  Memo1.Clear;
  for str in dfs do Memo1.Lines.Add(str);
end;

//使用 TDirectory.TFilterPredicate 函数参数
procedure TForm1.Button4Click(Sender: TObject);
var
  dfs: TStringDynArray;
begin
  Memo1.Clear;
  dfs := TDirectory.GetFileSystemEntries(path,
    function(const Path: string; const SearchRec: TSearchRec): Boolean
    begin
      //这里可以有更多过滤条件或其他处理
      Memo1.Lines.Add(Path + '\' + SearchRec.Name);
    end
  );
end;

end.

标签:Delphi,GetDirectories,dfs,TObject,IOUtils,procedure,str,TDirectory,Memo1
From: https://www.cnblogs.com/xionda/p/17623869.html

相关文章

  • delphi FastReport 打印设置
    FastReport打印设置属性和方法TfrxPrintOptions.CopiespropertyCopies:Integer;默认可打印份数。默认值为1。TfrxPrintOptions.DuplexpropertyDuplex:TfrxDuplexMode;全局双工设置。仅在准备报表后设置。TfrxPrintOptions.PrintModepropertyPrintMode:TfrxPrin......
  • delphi文章等
    在Delphi编程中的文件操作http://news.softhouse.com.cn/news/show/15723.htmldelphi关于文件操作的函数  http://www.cncfan.com/cncfan_com_article.asp?art_id=2502&cat_id=74关于文本文件http://www.75pc.com/viewthread.php?tid=2586,http://www.27a.cn/data/2006/0524/ar......
  • Delphi 10.x 提示脚本错误的解决方法
    解决办法如下:10.1版本修改方法:打开注册表,在cmd中输入regedit,以管理员的身份运行,找到HKEY_CURRENT_USER\SOFTWARE\Embarcadero\BDS\18.0\KnownIDEPackages项,找到$(BDS)\Bin\CommunityToolbar240.bpl这个子项目将其内容由EmbarcaderoCommunityToolbarPackage 改为_Em......
  • delphi 自带的JSON序列化类
    unitUnit1;interfaceusesWinapi.Windows,Winapi.Messages,System.SysUtils,System.Variants,System.Classes,Vcl.Graphics,Vcl.Controls,Vcl.Forms,Vcl.Dialogs,System.JSON.Serializers,Vcl.StdCtrls;typeTForm1=class(TForm)Memo1:TMemo......
  • DELPHI应用EXCEL(4) 使用TOLEContainer控件
    严格的来说,tolecontainer控件并不是一个EXCEL控件,而是一个所有OLE文件的控件,可以用它打开PDF、OFFICE、TXT文件等等。而且使用OLECONTAINER控件打开的文件,文件内容依旧是一个VARIANT类型的数据。OLECONTAINER控件在SYSTEM组下。 使用OLECONTAINER控件需要注意以下几点:1、一......
  • Delphi ShellExecute为应用程序传递多个参数
    开发环境DelphiXe11.3 调用的程序  procedureTForm2.Button1Click(Sender:TObject);begin//某个参数包含空格时(用""),如下面这行;这里传递过去是3个参数ShellExecute(handle,'open',pchar('C:\Users\PC\Desktop\新建文件夹\新建文件夹\Win32\Debug\Project2.ex......
  • Delphi应用EXCEL(3) 使用OLEOBJECT
    1、创建EXCEL的方法首先创建Excel对象,使用单元ComObj:VarExcelApp:Variant;beginExcelApp:=CreateOleObject(''Excel.Application'');使用OLEOBJECT创建的EXCEL应用程序是一个Variant类型,所以DELPHI不能自动补充语句,也没有帮助文件,需要到visualbasic......
  • DELPHI应用EXCEL(1)
    在介绍使用delphi控制excel之前前,我们首先需要了解关于EXCEL的几个基本概念:EXCEL应用程序、工作薄(book)、工作表(sheet)以及单元格(CELLS); 首先,我们是打开excel应用程序,并可设置应用程序可见或不可见,可以设置应用程序标题等等;没有管理工作簿(workbook)的应用程序是没有意义的,我......
  • Delphi使用Asterisk AMI接口给分机播放系统录音
    Delphi使用AsteriskAMI接口给分机播放系统录音查找资料在上一篇“Delphi调用Asterisk系统AMI接口取得来电号码”成功连接上AsteriskAMI接口取得来电号码,我们来测试用AMI来做点其它,比如说当系统出现故障后,给分机发送一个报警提醒,要怎么实现呢?经过查找资料我们发现在/var/lib/aster......
  • Delphi轻松读写NDEF文本、智能海报、应用控制等NFC标签
        NDEF全称NFCdataexchangeformat即nfc数据交换格式,是一种标准化的数据格式,可用于在任何兼容的NFC设备与另一个NFC设备或标签之间交换信息。数据格式由NDEF消息和NDEF记录组成。    NDEF信息可以写到不同类型的NFC芯片中,如NFC_Forum_Type2类的Ntag2x、FM1......