procedure tform1.DoSearch(dir, str: string);
var sr: tsearchrec;
begin
if FindFirst(dir + '*.*', faanyfile, sr) = 0 then
try
repeat
if ((sr.Attr and fadirectory) <> 0) and (sr.Name[1] <> '.') then
begin
FindAllFiles(dir + sr.Name + '/', str);
Dosearch(dir + sr.Name + '/', str);
end
until Findnext(sr) <> 0;
finally
findclose(sr);
end;
end;
procedure tform1.FindAllFiles(dir, str: string);
var sr: TSearchRec;
begin
if findfirst(dir + '*.*', faanyfile, sr) = 0 then
try
repeat
// if ScanInFile(dir + sr.Name, str, checkbox1.Checked) then
begin
inc(findn);
//memo1.Lines.Add(dir + sr.Name);
listbox1.Items.Add(dir + sr.Name);
end;
inc(nn);
statusbar1.SimpleText := format('Total scaned file: %d Found files: %d', [nn, findn]);
until FindNext(sr) <> 0;
finally
FindClose(sr);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
nn := 0;
findn := 0;
listbox1.Clear;
findallfiles('c:/','');
dosearch('c:/', '');
end;
这是我的一个程序中的一部分,列出c:上所有的文件以及文件夹,try,有些东西可以不管他
其实这也是从书上抄下来的
)