高分求解:如何查找指定目录及所有子目录中所有的.zip .rar .exe .mp3 文件,并将其文件名写入一指定 edit,请给出源码!

qufo 2002-08-19 08:32:43
高分求解:如何查找指定目录及所有子目录中所有的.zip .rar .exe .mp3 文件,并将其文件名写入一指定 edit,请给出源码!
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
foreveryday007 2002-08-19
  • 打赏
  • 举报
回复
DELPHI HELP,應該能看懂,我試過了沒有問題,再修改一下就差不多
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;

if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then

begin
with StringGrid1 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
while FindNext(sr) = 0 do
begin
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;
end;
FindClose(sr);
end;
end;
end;
debussy 2002-08-19
  • 打赏
  • 举报
回复
就是用FindFirst,FindNext递归啊。

为了效率,你可以用*.*通配符把所有文件名读入到一个StringList中,然后在这个StringList里面查找你需要的文件名

5,386

社区成员

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

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