procedure TDeleteDirFrm.findall(disk, path: String); var fpath: String; fs: TsearchRec; fileName:string; begin if over then exit; fpath:=disk+path+'\*.*'; if findfirst(fpath,faAnyFile,fs)=0 then begin if (fs.Name<>'.')and(fs.Name<>'..') then if (fs.Attr and faDirectory)=faDirectory then findall(disk,path+'\'+fs.Name) else fileName:=disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name))); if length(fileName)>70 then fileName:=copy(fileName,0,70)+'...'; label2.Caption := fileName; Application.ProcessMessages; //fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')'); while findnext(fs)=0 do begin if (fs.Name<>'.')and(fs.Name<>'..') then if (fs.Attr and faDirectory)=faDirectory then findall(disk,path+'\'+fs.Name) else begin //fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')'); fileName := disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name))); if length(fileName)>70 then fileName:=copy(fileName,0,70)+'...'; label2.Caption := fileName; Application.ProcessMessages; end end; end; findclose(fs); end;
看看Demo,你就明白了 procedure TForm1.Button1Click(Sender: TObject);var sr: TSearchRec; FileAttrs: Integer; begin StringGrid1.RowCount := 1; if CheckBox1.Checked then FileAttrs := faReadOnly else FileAttrs := 0; if CheckBox2.Checked then FileAttrs := FileAttrs + faHidden; if CheckBox3.Checked then FileAttrs := FileAttrs + faSysFile; if CheckBox4.Checked then FileAttrs := FileAttrs + faVolumeID; if CheckBox5.Checked then FileAttrs := FileAttrs + faDirectory; if CheckBox6.Checked then FileAttrs := FileAttrs + faArchive; if CheckBox7.Checked then FileAttrs := FileAttrs + faAnyFile; with StringGrid1 do begin RowCount := 0; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then begin repeat if (sr.Attr and FileAttrs) = sr.Attr then begin RowCount := RowCount + 1; Cells[1,RowCount-1] := sr.Name; Cells[2,RowCount-1] := IntToStr(sr.Size); end; until FindNext(sr) <> 0; FindClose(sr); end; end; end;
var
fpath: String;
fs: TsearchRec;
fileName:string;
begin
if over then exit;
fpath:=disk+path+'\*.*';
if findfirst(fpath,faAnyFile,fs)=0 then
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
findall(disk,path+'\'+fs.Name)
else
fileName:=disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)));
if length(fileName)>70 then fileName:=copy(fileName,0,70)+'...';
label2.Caption := fileName;
Application.ProcessMessages;
//fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
while findnext(fs)=0 do
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
findall(disk,path+'\'+fs.Name)
else begin
//fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
fileName := disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)));
if length(fileName)>70 then fileName:=copy(fileName,0,70)+'...';
label2.Caption := fileName;
Application.ProcessMessages;
end
end;
end;
findclose(fs);
end;
procedure TForm1.Button1Click(Sender: TObject);var
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then FileAttrs := FileAttrs + faAnyFile; with StringGrid1 do
begin
RowCount := 0; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then begin
repeat
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
end;