Var iList: Integer; tmpInputFile, tmpOutputFile, tmpEntry: String; tmpStrip, tmpListIn, tmpListOut: TStringList; Const ctDelim = '_'; ctSep = ','; ctQuote = '"'; ctOutputPath = 'C:\Test\Customer\Out\'; // Must end with a \ Begin psExitCode:= 0; tmpInputFile := psFilePath + psFilename; tmpOutputFile := ''; // BTW_Invites_20231023_1.csv tmpStrip := TStringList.Create; Try tmpStrip.Delimiter := ctDelim; tmpStrip.QuoteChar := #0; tmpStrip.StrictDelimiter := True; tmpStrip.DelimitedText := psFilename; If tmpStrip.Count >=4 Then Begin tmpOutputFile := tmpStrip.Strings[0] + ctDelim + 'Merged' + ctDelim + tmpStrip.Strings[2] + ctDelim + tmpStrip.Strings[3]; psLogWrite(1, '', 'OutputFile : ' + tmpOutputFile); End; Finally tmpStrip.Free; End; // If tmpOutputFile <> '' Then Begin tmpOutputFile := ctOutPutPath + tmpOutputFile; tmpListIn := TStringList.Create; tmpListOut := TStringList.Create; Try Try tmpListIn.LoadFromFile(tmpInputFile); // Check Output File If FileExists(tmpOutputfile) Then tmpListOut.LoadFromFile(tmpOutputFile); Try For iList := 0 to (tmpListIn.Count - 1) Do Begin tmpEntry := tmpListIn.Strings[iList] + ctSep + ctQuote + psFilename + ctQuote; tmpListOut.Add(tmpEntry); End; // Save To File Try tmpListOut.SaveToFile(tmpOutputFile); psExitCode := 1; Except psLogWrite(1, '', 'Exception SaveToFile: ' + tmpOutputFile); End; Except psLogWrite(1, '', 'Exception LoadFromFile: ' + tmpOutputFile); End; Except psLogWrite(1, '', 'Exception LoadFromFile: ' + tmpInputFile); End; Finally tmpListIn.Free; tmpListOut.Free; End; End Else psLogWrite(1, '', 'Error, empty output filename, did something change to the source filename structure?'); End.