一个超简单的问题:怎样取得一个目录下所有文件的列表?

lichp 2001-05-09 01:10:00
...全文
80 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sulin010 2001-05-31
  • 打赏
  • 举报
回复
若目录下有很多文件,速度势必较慢,能否通过读取文件分配表或其他更巧妙的方法???
sulin010 2001-05-31
  • 打赏
  • 举报
回复
小的无知,能否告知何为DELPHI猛料包
lichp 2001-05-14
  • 打赏
  • 举报
回复
好,加分喽
lichp 2001-05-09
  • 打赏
  • 举报
回复
有吗?我临时遇上的,没仔细去查里边。
Kingron 2001-05-09
  • 打赏
  • 举报
回复
lichp(书生有驴情为径,绝海无鸭哭作粥!) :
你怎么不看看那个Delphi猛料包?里面有的。
lichp 2001-05-09
  • 打赏
  • 举报
回复
嗯?这么长啊,我回去试试
rh 2001-05-09
  • 打赏
  • 举报
回复
laza(秋高蓝) (2001-1-6 15:32:00) 得10分
这是我平时写的一个递归函数,检索某路径下的所有文件包括所有的子文件夹的文件,文件被保存到文件中。
form1中有edit1写入路径。listbox显示文件。
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
FNewPath: string;
procedure DoSearchPathFile(qPath: string);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Clear;
DoSearchPathFile(Edit1.Text);

end;

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

procedure TForm1.DoSearchPathFile(qPath: string);
var
SR: TSearchRec;
FileAttr: Integer;
begin
FileAttr := faDirectory;
FindFirst(qPath + '\*.*', FileAttr, SR);

While FindNext(SR) = 0 do
begin
if (SR.Name <> '.') and (SR.Name <> '..') then begin
if DirectoryExists(qPath + '\' + SR.Name) then
begin
ListBox1.Items.Add('路径'+ qPath + '\' + SR.Name);
DoSearchPathFile(qPath + '\' + SR.Name);

end;
//;else ListBox1.Items.Add(qPath + '\' + SR.Name);

end;
end;

FileAttr := faAnyFile;

FindFirst(qPath + '\*.*', FileAttr, SR);
while FindNext(SR) = 0 do
begin
if (SR.Name <> '.') and (Sr.Name <> '..') then
begin
if not(DirectoryExists(qPath + '\' + SR.Name)) then
ListBox1.Items.Add(qPath + '\' + SR.Name);
end;
end;
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin

if key = vk_Return then
begin
if Trim(Edit1.Text) = '' then
begin
ShowMessage('Invalid PathName');
Exit;
end;

FNewPath := Edit1.Text[Length(Edit1.Text)];
if FNewPath = '\' then
FNewPath := Copy(Edit1.Text, 1, Length(Edit1.Text) - 1)
else
begin
FNewPath := Edit1.Text;
end;

ListBox1.Clear;
DoSearchPathFile(FNewPath);

end;


end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
self.ListBox1.Items.SaveToFile('FileList.txt');
end;

end.

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧