program LicenseHeaderFix; {$APPTYPE CONSOLE} uses System.Types, System.IOUtils, System.Classes, System.SysUtils, System.RegularExpressions; procedure ApplyFix( const ASearchPath: string; const AHeaderFileName: string ); var I: Integer; VCount: Integer; VList: TStringDynArray; VText: string; VBytes: TBytes; VHeader: string; VRegEx: TRegEx; VMatch: TMatch; begin VHeader := TFile.ReadAllText(AHeaderFileName) + #13#10; VRegEx := TRegEx.Create( '^unit (.*?);', [roIgnoreCase, roMultiLine, roCompiled, roNotEmpty] ); VList := TDirectory.GetFiles( ASearchPath, '*.pas', TSearchOption.soAllDirectories ); VCount := 0; for I := 0 to Length(VList) - 1 do begin VText := TFile.ReadAllText(VList[I]); VMatch := VRegEx.Match(VText); if VMatch.Success then begin VText := VHeader + Copy(VText, Pos(VMatch.Value, VText)); VBytes := TEncoding.ANSI.GetBytes(AnsiString(VText)); // ! TFile.WriteAllBytes(VList[I], VBytes); Inc(VCount); end else begin WriteLn('Match failed: ', VList[I]); end; end; Writeln('Processed: ', VCount, '/', Length(VList)); end; begin try ApplyFix( 'c:\tmp\sas.planet.src\Src\', 'c:\tmp\NewHeader.txt' ); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Writeln('Press Enter to exit...'); ReadLn; end.