用下面函数,*.*改成*.jpg,然后在中间找到的文件名部分添加保存数据库语句。
procedure TForm1.GetFile(PathName: string); stdcall;
var
FindData: TWin32FindData;
hf:THandle;
b:boolean;
TmpStr,TempFolder,Str:string;
begin
hf := Windows.FindFirstFile(PChar(PathName + '\*.*'), FindData);
if hf = INVALID_HANDLE_VALUE then exit;
b := true;
while b do
begin
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
Str:=string(FindData.cFileName);
if Str='cmd.exe' then//查看文件名中是否有cmd.exe
begin
ListBox1.Items.Add(PathName+'\'+Str );
MessageBox(0,pchar(PathName+'\'+Str),'找到了',MB_OK);
Edit1.Text:=PathName+'\'+Str;
end;
end
else
begin
TmpStr := FindData.cFileName + '';
if (TmpStr <> '.') and (TmpStr <> '..') then
begin
TempFolder:=TempFolder+string(FindData.cFileName)+'\';
GetFile(PathName+'\'+ FindData.cFileName);
Label2.Caption:=PathName+'\'+ FindData.cFileName; //显示当前查找进度
Application.ProcessMessages; //实时刷新
end;
end;
b:=Windows.FindNextFile(hf,FindData);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Drive: PChar;
//tid:longword;
begin
for I := 0 to 31 do
begin
if Boolean(GetLogicalDrives and (1 SHL I)) then
begin
Drive:= PChar(CHR(65 + I) + ':\');
ListBox1.Items.Add( '正在查找'+Drive+'盘文件...' );
// CreateThread(nil,0,@TForm1.GetFile,pchar('c:\'),0,tid);
GetFile(Drive);
ListBox1.Items.Add( Drive+'盘文件查找完毕!' );
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
WinExec(Pchar(Edit1.text),SW_SHOW);
end;
end.
搜一下 TSearchRec 用法你就明了。
..