delphi搜索目录代码

来源:百度知道 编辑:UC知道 时间:2024/09/24 03:18:39
比如有一个目录里面有一个 ceshi.exe
写个代码搜索本地搜索硬盘,找到该程序的目录,如何用delphi写代码呢,最好每行代码写个注释,谢谢咯!
这个代码怎么用啊,我不会用啊!代码复制到空白处了,按钮里面写什么代码呢?

N年没有Delphi了。

以下是Copy的。

procedure SearchPath(const APath: string); //APath必须带'\'
var
SR: TSearchRec;
begin
if FindFirst(APath + '*.*', faAnyFile, SR) = 0 then
repeat
if (SR.Name <> '.') and (SR.Name <> '..') and
(SR.Attr = faDirectory) then
begin
ListBox1.Items.Add(APath + SR.Name);
SearchPath(APath + SR.Name + '\');
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;

//查找指定目录下面的所有文件
procedure findAll(tmp:string;ss:TStrings);

procedure findAll(tmp:string;ss:TStrings);
var
sc:TSearchRec;
begin
//*.*代表找所有的文件,如果你改成*.mp3就是找mp3文件
if FindFirst(tmp+'