在单个文件夹中如何实现文件查找?(50分)

  • 主题发起人 tianyu717
  • 开始时间
T

tianyu717

Unregistered / Unconfirmed
GUEST, unregistred user!
在单个文件夹中如何实现文件查找?
如:在abc/中查找*.mdb.要求列出文件清单。
谢谢。
我还是个小新手,请写详细些。。。。。。。。。。
 
DELPHI 帮助中的Sample
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;
 
这里调用了Win32 APId的GetCurrentDirectory函数,
按照这样去设计一下你就会明白的:
首先你在FORM上放置一个FileListBox{在Win31控件栏}控件;
然后将FileListBox的Mask属性设为*.mdb;
之后双击FORM,输入如下代码:
procedure TForm1.FormCreate(Sender: TObject);
var
WDir:String;
begin
SetLength(WDir,144);
if GetCurrentDirectory(PChar(WDir),144)<>0 then
begin
SetCurrentDirectory(PChar(dir));
SetLength(WDir,StrLen(PChar(WDir)));
dir:=WDir+'/abc';
FileListBox1.Directory:=dir;
end
else
RaiseLastWin32error;
end;
 
Delphi自带了一大堆的例子,为何不去看看呢?
那些程序都不错的
 
多人接受答案了。
 
顶部