このコードを実装しましたが、もう一度サブディレクトリを検索することはできません。Delphiのすべてのサブディレクトリでファイルを検索するには
procedure TFfileSearch.FileSearch(const dirName:string);
begin
//We write our search code here
if FindFirst(dirName,faAnyFile or faDirectory,searchResult)=0 then
begin
try
repeat
ShowMessage(IntToStr(searchResult.Attr));
if (searchResult.Attr and faDirectory)=0 then //The Result is a File
//begin
lbSearchResult.Items.Append(searchResult.Name)
else
begin
FileSearch(IncludeTrailingBackSlash(dirName)+searchResult.Name);
//
end;
until FindNext(searchResult)<>0
finally
FindClose(searchResult);
end;
end;
end;
procedure TFfileSearch.btnSearchClick(Sender: TObject);
var
filePath:string;
begin
lbSearchResult.Clear;
if Trim(edtMask.Text)='' then
MessageDlg('EMPTY INPUT', mtWarning, [mbOK], 0)
else
begin
filePath:=cbDirName.Text+ edtMask.Text;
ShowMessage(filePath);
FileSearch(filePath);
end;
end;
E:\ドライブに* .iniファイルの検索を指定しています。最初のfilePathはE:* .iniです。 しかし、コードはE:\ドライブのディレクトリを検索しません。それを修正するには?あなたはFindFirst
への呼び出しでファイルの拡張子に制限を適用することはできませんアドバンス
http://stackoverflow.com/questions/ 6536525/delphi/6536733#6536733 –