I would like to search specific string in several files.
e.g. oem1.inf
oem2.inf
oem5.inf
oem8.inf
...
All the target file names have the same format - oem*.inf
I want to search specific substring (e.g. "1234"
in "ABA1234"
) in these files.
I have referenced Inno setup search for existing file, but it's a little different from my question.
I could get all path now:
Var
FilesFound: Integer;
FindRec: TFindRec;
Stemp: String;
begin
FilesFound := 0;
if FindFirst('C:\Path\oem*.inf', FindRec) then begin
try
repeat
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
begin
temp := 'C:\Path\' + FindRec.Name;
MsgBox(temp, mbInformation, MB_OK);
FilesFound := FilesFound + 1;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
MsgBox(IntToStr(FilesFound) + ' files found in the System directory.',
mbInformation, MB_OK);
end;
I solved this question. Thanks Martin and Ken.
Var
FindRec: TFindRec;
I: Integer;
Tag: String;
Line: String;
FileLines: TStringList;
begin
if FindFirst('C:\PATH\oem*.inf', FindRec) then
begin
try
FileLines := TStringList.Create;
Tag := 'ABA1234';
repeat
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
begin
FileLines.LoadFromFile('C:\PATH\' + FindRec.Name);
for I := 0 to FileLines.Count - 1 do
begin
Line := FileLines[I];
if (Pos(Tag, Line) > 0) then
MsgBox(temp, mbInformation, MB_OK);
end;
end;
until not FindNext(FindRec);
finally
FileLines.Free;
FindClose(FindRec);
end;
end;
end;