Var iInput, tmpCount, tmpOrgNo: Integer; tmpCol4, tmpFile, tmpOutputFile,tmpPipeEntry: String; tmpPipe, tmpInput, tmpOutput: TStringList; Const ctPipe = '|'; ctCsv = '.csv'; ctOutput = 'C:\Test\Rvman\Out\'; // Must end with a \ Begin psExitCode:= 0; tmpFile := psFilePath + psFileName; tmpOrgNo := 0; psLogWrite(1, '', 'Load Data From File: ' + tmpFile); tmpInput := TStringList.Create; tmpOutput := TStringList.Create; Try Try tmpInput.LoadFromFile(tmpFile); If tmpInput.Count > 0 Then Begin Repeat tmpCount := tmpInput.Count - 1; tmpPipe := psDelimitedTextAsList(ctPipe, tmpInput.Strings[tmpCount]); If Assigned(tmpPipe) Then Begin If tmpPipe.Count >= 4 Then Begin tmpCol4 := tmpPipe.Strings[3]; psLogWrite(1, '', 'Col4: ' + tmpCol4); For iInput := (tmpInput.Count-1) Downto 0 Do Begin tmpPipeEntry := tmpInput.Strings[iInput]; If Pos(ctPipe + tmpCol4 + ctPipe, tmpPipeEntry) <> 0 Then Begin psLogWrite(1, '', 'Added Data to Output List: ' + tmpPipeEntry); tmpOutput.Insert(0, tmpPipeEntry); tmpInput.Delete(iInput); End; End; // Create Output File If tmpOutput.Count > 0 Then Begin If tmpOrgNo = 0 Then tmpOutputFile := ctOutput + psFileName Else tmpOutputFile := ChangeFileExt(ctOutput + psFileName, IntToStr(tmpOrgNo) + ctCsv); // Increment tmpOrgNo := tmpOrgNo + 1; // Save To File Try tmpOutput.SaveToFile(tmpOutputFile); tmpOutput.Clear; psLogWrite(1, '', 'SaveToFile ' + tmpOutputFile + ' Successful'); Except psLogWrite(1, '', 'SaveToFileError, ' + tmpOutputFile); Break; // Break On Error End; End; End Else Begin tmpInput.Delete(tmpCount); psLogWrite(1, '', 'Data Count Error at row: ' + IntToStr(tmpCount) + ' of File: ' + tmpFile); End; // Free tmpPipe.Free; End; // Set Result If tmpInput.Count = 0 Then psExitCode := 1; until psExitCode = 1; End Else psLogWrite(1, '', 'No Data available in File: ' + tmpFile); Except psLogWrite(1, '', 'LoadFromFileError, ' + tmpFile); End; Finally tmpInput.Free; tmpOutput.free End; End.