怎样查找文件(100分)

  • 主题发起人 主题发起人 ktsxy
  • 开始时间 开始时间
K

ktsxy

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个查找文件的小程序.
要求
查找指定几个目录下的所以子目录及指定文件.并将写入数据库中.(文件名.路径+文件名)
查找可以使用通配符..
如我要同时查找
d:/abc e:/deb f:/abew ......
怎样实现.可以一个个目录的查.但要保证多10个可选目录

能否发一份源码给我.谢谢
ktsxy@sohu.com
 
遍历文件夹,findfist,findnext。。。也就用这两函数就够了
 
to:foxphone2003

帮个忙了
 
unit MainFrm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, FileCtrl, Grids, Outline, DirOutln;

type
TMainForm = class(TForm)
dcbDrives: TDriveComboBox;
edtFileMask: TEdit;
lblFileMask: TLabel;
btnSearchForFiles: TButton;
lbFiles: TListBox;
dolDirectories: TDirectoryOutline;
procedure btnSearchForFilesClick(Sender: TObject);
procedure dcbDrivesChange(Sender: TObject);
private
FFileName: String;
function GetDirectoryName(Dir: String): String;
procedure FindFiles(APath: String);
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

function TMainForm.GetDirectoryName(Dir: String): String;
begin
if Dir[Length(Dir)]<> '/' then
Result := Dir+'/'
else
Result := Dir;
end;

procedure TMainForm.FindFiles(APath: String);
var
FSearchRec,
DSearchRec: TSearchRec;
FindResult: integer;

function IsDirNotation(ADirName: String): Boolean;
begin
Result := (ADirName = '.') or (ADirName = '..');
end;

begin
APath := GetDirectoryName(APath);
FindResult := FindFirst(APath+FFileName,faAnyFile+faHidden+
faSysFile+faReadOnly,FSearchRec);
try
while FindResult = 0 do
begin
lbFiles.Items.Add(LowerCase(APath+FSearchRec.Name));
FindResult := FindNext(FSearchRec);
end;

FindResult := FindFirst(APath+'*.*', faDirectory, DSearchRec);

while FindResult = 0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not
IsDirNotation(DSearchRec.Name) then
FindFiles(APath+DSearchRec.Name);
FindResult := FindNext(DSearchRec);
end;
finally
FindClose(FSearchRec);
end;
end;

procedure TMainForm.btnSearchForFilesClick(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
try
lbFiles.Items.Clear;
FFileName := edtFileMask.Text;
FindFiles(dolDirectories.Directory);
finally
Screen.Cursor := crDefault;
end;
end;

procedure TMainForm.dcbDrivesChange(Sender: TObject);
begin
dolDirectories.Drive := dcbDrives.Drive;
end;

end.
 
sysutils.FindClose(FSearchRec);最稳妥
 
用多线程 这是写程序必备的 然后自己写个PAS 要查询目录还是文件
 
谁能发一个小程序源码给我.谢谢

邮件: ktsxy@sohu.com
 
后退
顶部