在delphi6中,如何来实现类似于windows自带的“搜索文件”这项功能呢?并且要得到该文件所在的地址。
例如,我在edit1中输入要查询的文件名是123,要在D:盘下面来查,输入好这两项以后,点击“查询”按钮,如果有D盘有该文件,则该文件的绝对路径显示在label1中,没有查到则弹出反馈信息:对不起,没有你要查找的文件!
还请高手帮忙!
例如,我在edit1中输入要查询的文件名是123,要在D:盘下面来查,输入好这两项以后,点击“查询”按钮,如果有D盘有该文件,则该文件的绝对路径显示在label1中,没有查到则弹出反馈信息:对不起,没有你要查找的文件!
还请高手帮忙!
解决方案 »
- insert into 语法错误
- hjy2 := inttohex(hjy,4); 的结果如果溢出了,那怎么取高字节和低字节啊?
- 新手问题 字符串和PChar之间的关系
- fieldbyname
- 请问高手,如何用最简单方法判断一个字段是否是不断增大的?
- delphi如何计算出一分钟中的最后一秒
- DBGrid中如何确定那一行被选择了?
- delphi7,怎样用socket传文本?
- 关于数据库,急急急!!!
- 报错:line too long (more than 1023 charachers) 原因是什么?
- dbgridEh的wordwrap功能问题!??
- 各为大虾请进,如何将USB接口的摄象头的当前桢中所选取的区域保存为BMP图象?100!!!
这方面的内容好像有人提出过,你可以在论坛搜索一下...
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;
参见findfirst 和findnext可以满足你的要求
还有就是,我要查询的内容在哪里输入?盘符呢?又在那里输入?望您指点一二!小人不胜感激!
//----开始触发点击搜索按钮事件
procedure TForm1.Button1Click(Sender: TObject);var
sr: TSearchRec;//搜索函数 详见delphi自带帮助
FileAttrs: Integer;//用来保存7个CheckBox的值 这7个CheckBox是为了让你完成类似windows搜索的高级选项的 例如你选择了CheckBox1 那么只搜索只读文件。
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//看到edit1了吗 那就是你要填入查询的地方
begin
repeat
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1,RowCount-1] := sr.Name;。//“FindFirst”搜索第一个符合条件的文件
并显示在StringGrid中
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
until FindNext(sr) <> 0;继续搜索符合条件的文件
并显示在StringGrid中
FindClose(sr);
end;
end;
end;
参见findfirst 和findnext可以满足你的要求
----------------------------------------------------------
我也是初学delphi 如有错误 望高手指点