How to filter files based on reading their content header data
Q: How to filter file from read content in file. Header data date=today yyyymmdd
I want is as shown in the picture below.
A: In this case the Source must be a Windows folder or share:
Test file inside of: C:\Test\Customer\In\
Please open our Pascal Script option:
Please enable and add the following ‘On Destination’ Pascal Script:
Var
iList: Integer;
tmpCurrentDate, tmpEntry, tmpFile: String;
tmpList: TStringList;
Const
ctRunDate = 'RUNDATE=';
Begin
psVSA := '';
psExitCode:= -2;
tmpCurrentDate := FormatDateTime('YYYYMMDD', Now);
tmpFile := psFilePath + psFileName;
psLogWrite(1, '', 'Searching for RUNDATE inside File: ' + tmpFile);
tmpList := TStringList.Create;
Try
Try
tmpList.LoadFromFile(tmpFile);
// Iterate
For iList := 0 to (tmpList.Count - 1) Do
Begin
tmpEntry := AnsiUpperCase(tmpList.Strings[iList]);
If pos(ctRunDate, tmpEntry) <> 0 Then
Begin
tmpEntry := psStringReplace(tmpEntry, ctRunDate, '');
If tmpEntry <> '' Then
Begin
If SameText(tmpEntry, tmpCurrentdate) Then
Begin
psExitCode := 1; // Filter found
// Debug
psLogWrite(1, '', 'Valid RUNDATE found: ' + tmpEntry);
// Break
Break;
End;
End;
End;
End;
Except
psLogWrite(1, '', 'LoadFromFileError, ' + tmpFile);
End;
Finally
tmpList.Free;
End;
End.
We added the following filename include filter because it is important to only process text based files:
We added a Windows folder as Destination:
RunTime Log result:
#filehandling #filetransfer #filemanagement
If you need any help with this ‘filter files based on reading their content header data’ request, please let us know.
Best Regards,
Limagito Team