⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 delphi 的文件查找和遍历
💻 PAS
字号:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    RichEdit1: TRichEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    tmppath:string;
    filecount:integer;
    procedure filefind(stpath,prpath: string);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
{if OpenDialog1.Execute then
  begin
    tmppath:=OpenDialog1.FileName;

      end;}
      SelectDirectory('文件路径','',tmppath);
      filecount:=0;
      filefind(tmppath+'\','');
      RichEdit1.Lines.Add('file :'+inttostr(filecount));
end;

procedure TForm1.filefind(stpath,prpath: string);
var
  sr: TSearchRec;
  FileAttrs: Integer;
  filepath,dirpath:string;
begin
  FileAttrs := 0;
  FileAttrs := FileAttrs + faAnyFile;
  dirpath:= stpath+prpath+'*.*';

  if FindFirst(dirpath, FileAttrs, sr) = 0 then

    begin
      repeat
      if (sr.Attr and faDirectory)<>0 then
      begin

      if (sr.Name = '.') or (sr.Name = '..') then
          begin
          end
          else
            filefind(stpath,prpath+sr.Name+'\');
      end
      else
      begin
      RichEdit1.Lines.Add(prpath+sr.Name);
      filecount:=filecount+1;
      end;
       
      until FindNext(sr) <> 0;
      FindClose(sr);
    end;



end;

procedure TForm1.FormShow(Sender: TObject);
begin
     tmppath:='c:\';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -