Answer the question
In order to leave comments, you need to log in
Search and replace all text data in txt files of a folder, is there any software?
Hello everyone, I want to know if there is such software. For example, I specify a folder with txt files, the program opens each one, looks for what is needed and replaces this one in all. I have such a situation, each file contains the address of the local server, you need to change it, and there are a lot of them in order to save time, I run the program, it searches for all test1.ru and replaces it with the one I need. Is there such a program?
Answer the question
In order to leave comments, you need to log in
procedure TMainFM.DoLine( Path: String );
var SearchRec: TSearchRec;
Result: Integer;
FC: TStringList;
begin
FC := TStringList.Create;
Result := FindFirst( Path + '*.*', faAnyFile, SearchRec);
while DoIt and ( Result = 0 ) do begin
// Рекурсия папок:
if ( SearchRec.Attr and faDirectory ) <> 0 then begin
if Copy( SearchRec.Name, 1, 1 ) <> '.' then DoLine( Path + SearchRec.Name + '\');
end else begin
if ( ExtractFileExt( SearchRec.Name ) = laExt.Text ) then begin
FC.LoadFromFile( Path + SearchRec.Name );
if Pos( edFind.Text, FC.Text ) > 0 then begin
FC.Text := StringReplace( FC.Text, edFind.Text, edChange.Text, [ rfReplaceAll ]);
FC.SaveToFile( Path + SearchRec.Name );
Inc( FChange );
laChange.Text := IntToStr( FChange );
lbFile.Items.Add( Path + SearchRec.Name + ' [замена]' );
end else begin
lbFile.Items.Add( Path + SearchRec.Name );
end;
Inc( FFind );
laAll.Text := IntToStr( FFind );
lbFile.ItemIndex := ( lbFile.Items.Count - 1 );
end;
end;
Application.ProcessMessages;
Result := FindNext( SearchRec );
end;
FindClose( SearchRec );
FC.Free;
if Path = laPath.Text then DoIt := False;
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question