入
入门
Unregistered / Unconfirmed
GUEST, unregistred user!
unit guangquguan;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure FindFile(path:string);
end;
var
Form1: TForm1;
SearchRec: TSearchRec;
F: TextFile;
s:string;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
FindFile(Edit1.Text);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
assignfile(f,'e:/text.txt');
append(F);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
postquitmessage(0);
end;
procedure TForm1.FindFile(path:string);
var
path1:string;
begin
try
FindFirst(path+'*.*',faAnyFile{ and not faDirectory}, SearchRec);
if FindNext(SearchRec)<>0 then PostQuitMessage(0);
while FindNext(SearchRec) = 0 do
begin
s:=string(Searchrec.Name);
writeln(f,s);
if (SearchRec.Attr and fadirectory>0) then
begin
writeln(f,'');
try
path1:=path+String(SearchRec.Name)+'/';
Form1.FindFile(path1);
except
PostQuitMessage(0);
end;
end;
end;
FindClose(SearchRec);
except
FindClose(SearchRec);
PostQuitMessage(0);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
CloseFile(F);
end;
end.
我想让此程序按照递归的方法查找指定目录下的全部内容(包括所有子文件夹及
文件),但是他总是达不到预期目的。
举个例子说,D盘下有如下文件及文件夹:
文件夹:WIN98,PICTURES,CD,MP3;
文件:新建 文本文档.txt,新建 文本文档(2).txt
此程序运行后在EDIT1内填上D:/,则在文件text.txt中出现的是:
desktop.ini
新建 文本文档.txt
mp3
11.MP3
水手.mp3
月亮.mp3
墮落天使.mp3
迟来的春天.mp3
一生不变.mp3
幻影.mp3
想和你吹风.mp3
爱的根源.mp3
都市恋歌.mp3
爱在深秋.mp3
你給我的爱最多.mp3
谁可改变.mp3
LINDA.mp3
一路上有你.mp3
相信她.mp3
desk
我实在找不出原因,请各位打下指点。
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure FindFile(path:string);
end;
var
Form1: TForm1;
SearchRec: TSearchRec;
F: TextFile;
s:string;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
FindFile(Edit1.Text);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
assignfile(f,'e:/text.txt');
append(F);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
postquitmessage(0);
end;
procedure TForm1.FindFile(path:string);
var
path1:string;
begin
try
FindFirst(path+'*.*',faAnyFile{ and not faDirectory}, SearchRec);
if FindNext(SearchRec)<>0 then PostQuitMessage(0);
while FindNext(SearchRec) = 0 do
begin
s:=string(Searchrec.Name);
writeln(f,s);
if (SearchRec.Attr and fadirectory>0) then
begin
writeln(f,'');
try
path1:=path+String(SearchRec.Name)+'/';
Form1.FindFile(path1);
except
PostQuitMessage(0);
end;
end;
end;
FindClose(SearchRec);
except
FindClose(SearchRec);
PostQuitMessage(0);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
CloseFile(F);
end;
end.
我想让此程序按照递归的方法查找指定目录下的全部内容(包括所有子文件夹及
文件),但是他总是达不到预期目的。
举个例子说,D盘下有如下文件及文件夹:
文件夹:WIN98,PICTURES,CD,MP3;
文件:新建 文本文档.txt,新建 文本文档(2).txt
此程序运行后在EDIT1内填上D:/,则在文件text.txt中出现的是:
desktop.ini
新建 文本文档.txt
mp3
11.MP3
水手.mp3
月亮.mp3
墮落天使.mp3
迟来的春天.mp3
一生不变.mp3
幻影.mp3
想和你吹风.mp3
爱的根源.mp3
都市恋歌.mp3
爱在深秋.mp3
你給我的爱最多.mp3
谁可改变.mp3
LINDA.mp3
一路上有你.mp3
相信她.mp3
desk
我实在找不出原因,请各位打下指点。